Determining Next sequence of number if there are 7 sequences each starting with a letter

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
929
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for a formula that can determine the next sequence of a number from another sheet if there are 7 sequences each starting with a letter. For example:

A001
B001
C001
D001
E001
F001
G001

I know that formula: =MAX('Sheet1'!A$1:A$1000000)+1 works to find the next sequence of a number but I have 7 number sequences.
I was thinking that when the user enters the correct letter (aka: G) in a certain cell that, maybe was a way to do an index/match and IF function to find the next sequence in the cells that match "G".

Maybe someone will be able to help.

Thank you

Carla
 
Is there a way if C1 is blank that it gives a "" result? currently if C1 is blank it gives 001
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I have one more question. How would the formula look if my data was on sheet 1, column A but my reference cell (C1) was on sheet 2?
 
Upvote 0
Try
=IF(C$1="","",C$1&TEXT(MAX(IF(LEFT(A$1:A$22)=C$1,0+MID(A$1:A$22,2,4)))+1,MID("0000",1+(C$1<>"B"),4)))
 
Upvote 0
That is perfect. and I referenced the other sheet so all is good.

=IF(C$1="","",C$1&TEXT(MAX(IF(LEFT(Sheet1!A$1:A$22)=C$1,0+MID(Sheet1!A$1:A$22,2,4)))+1,MID("0000",1+(C$1<>"B"),4)))

I wish I understood the logic of the formula though. This is beyond my experience.
 
Upvote 0
If you select the cell with the formula, then on the formulas tab select "Evaluate formula" you can step through the evaluation process to see what each part does.
 
Upvote 0
Thank you very much. I am still learning how to write complex formulas and vba code. I appreciate all of your guys help so much.

Thank you again :)

Carla
 
Upvote 0
I went through the evaluation process but am definitely still confused.

=IF(C$1="","",C$1&TEXT(MAX(IF(LEFT(Sheet1!A$1:A$22)=C$1,0+MID(Sheet1!A$1:A$22,2,4)))+1,MID("0000",1+(C$1<>"B"),4)))

I understand if C1 is blank, return a blank. not sure the C1&Text...perhaps stating to look for text in C1..., The Max is finding the next number, the If is stating another condition (I am assuming the matching between C1 and column A in Sheet1). I don't fully understand the Left function as I have never used it before but I think it is isolating the left letter in the column (example G) and saying if it equals C1....but after that I get lost.... Never used MID before either and definitely don't understand the C1<>"B" or why do we use absolute values (cntrl+Shift+enter).
Anyway I doubt you have time to elaborate. Thank you for providing the formula, I hope to fully understand this all one day.
 
Upvote 0
Or, try this shorter non-array formula :

=IF(C$1="","",C$1&TEXT(RIGHT(IFNA(LOOKUP(1,0/(C$1=LEFT(A:A)),A:A),0),3)+1,REPT(0,(C$1="B")+3)))

Regards
Bosco
 
Last edited:
Upvote 0
Or, try this shorter non-array formula :

=IF(C$1="","",C$1&TEXT(RIGHT(IFNA(LOOKUP(1,0/(C$1=LEFT(A:A)),A:A),0),3)+1,REPT(0,(C$1="B")+3)))
For future readers of this thread, Bosco's formula above will only work on Excel 2013 or later... if you are using Excel 2010 (like I am) or earlier, his formula will generate a #NAME ? error (the IFNA function will be the cause).
 
Last edited:
Upvote 0
Or, try this shorter ... formula :

=IF(C$1="","",C$1&TEXT(RIGHT(IFNA(LOOKUP(1,0/(C$1=LEFT(A:A)),A:A),0),3)+1,REPT(0,(C$1="B")+3)))
I assume the 'shorter' comment relates to the formula in post 13 as the subsequent formulas take into account the multiple sheets. Whilst it is (slightly) shorter, it is only shorter because the whole of column A is referenced instead of just A1:A22 and whilst it does shorten the formula it also increases the calculation time more than 50-fold by my measurement.

I suggest another non-array & even shorter formula (still on 1 sheet to compare with posts 13 & 18) that also calculates at a comparable speed to post 13.

=IF(C$1="","",C$1&AGGREGATE(14,6,MID(A$1:A$22,2,9)/(LEFT(A$1:A$22,1)=C1),1)+1)

Adapted to the column data being on Sheet1 it would become
=IF(C$1="","",C$1&AGGREGATE(14,6,MID(Sheet1!A$1:A$22,2,9)/(LEFT(Sheet1!A$1:A$22,1)=C1),1)+1)
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top