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

#### willow1985

##### Active Member
Is there a way if C1 is blank that it gives a "" result? currently if C1 is blank it gives 001

### Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

#### willow1985

##### Active Member
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
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

##### Active Member
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
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

##### Active Member
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

##### Active Member
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
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
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
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)

• willow1985

1,095,186
Messages
5,442,905
Members
405,206
Latest member
Neetish_93

### This Week's Hot Topics

• Copy entire row if CountA <>0 to another sheet
[B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
• Select last used Row in Table
I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
• excel workbook: do not allow certain file name
Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
• fixing problem autofilter
hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
• “Weight”
Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
• How to capitalize everything before a certain character?
In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...