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

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
524
Office Version
2019
Platform
Windows
Is there a way if C1 is blank that it gives a "" result? currently if C1 is blank it gives 001
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
524
Office Version
2019
Platform
Windows
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
41,308
Office Version
365
Platform
Windows
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)))
 

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
524
Office Version
2019
Platform
Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
41,308
Office Version
365
Platform
Windows
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.
 

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
524
Office Version
2019
Platform
Windows
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
 

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
524
Office Version
2019
Platform
Windows
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.
 

bosco_yip

Well-known Member
Joined
Dec 2, 2002
Messages
1,938
Office Version
2019
Platform
Windows
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:

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,965
Office Version
2010
Platform
Windows
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:

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
44,787
Office Version
365
Platform
Windows
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,100,209
Messages
5,473,189
Members
406,850
Latest member
thesmallfry123

This Week's Hot Topics

Top