Edit Formula To Return Leading Zeroes

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,860
How do I get the formula in Col's F:J return the value for leading zeroes?
Excel Workbook
ABCDEFGHIJ
10212172136#N/ACSCS
21121323336DCCDS
31116182230DSSDS
40307102636#N/A#N/ACSS
Sheet2
Excel 2007
Cell Formulas
RangeFormula
F1=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(A1,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(A1,{1,2},1)+0)+{0,1},MID(A1,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(A1,{1,2},1)+0,MID(A1,{1,2},1)+0))))
F2=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(A2,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(A2,{1,2},1)+0)+{0,1},MID(A2,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(A2,{1,2},1)+0,MID(A2,{1,2},1)+0))))
F3=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(A3,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(A3,{1,2},1)+0)+{0,1},MID(A3,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(A3,{1,2},1)+0,MID(A3,{1,2},1)+0))))
F4=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(A4,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(A4,{1,2},1)+0)+{0,1},MID(A4,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(A4,{1,2},1)+0,MID(A4,{1,2},1)+0))))
G1=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(B1,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(B1,{1,2},1)+0)+{0,1},MID(B1,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(B1,{1,2},1)+0,MID(B1,{1,2},1)+0))))
G2=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(B2,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(B2,{1,2},1)+0)+{0,1},MID(B2,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(B2,{1,2},1)+0,MID(B2,{1,2},1)+0))))
G3=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(B3,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(B3,{1,2},1)+0)+{0,1},MID(B3,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(B3,{1,2},1)+0,MID(B3,{1,2},1)+0))))
G4=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(B4,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(B4,{1,2},1)+0)+{0,1},MID(B4,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(B4,{1,2},1)+0,MID(B4,{1,2},1)+0))))
H1=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(C1,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(C1,{1,2},1)+0)+{0,1},MID(C1,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(C1,{1,2},1)+0,MID(C1,{1,2},1)+0))))
H2=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(C2,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(C2,{1,2},1)+0)+{0,1},MID(C2,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(C2,{1,2},1)+0,MID(C2,{1,2},1)+0))))
H3=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(C3,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(C3,{1,2},1)+0)+{0,1},MID(C3,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(C3,{1,2},1)+0,MID(C3,{1,2},1)+0))))
H4=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(C4,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(C4,{1,2},1)+0)+{0,1},MID(C4,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(C4,{1,2},1)+0,MID(C4,{1,2},1)+0))))
I1=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(D1,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(D1,{1,2},1)+0)+{0,1},MID(D1,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(D1,{1,2},1)+0,MID(D1,{1,2},1)+0))))
I2=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(D2,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(D2,{1,2},1)+0)+{0,1},MID(D2,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(D2,{1,2},1)+0,MID(D2,{1,2},1)+0))))
I3=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(D3,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(D3,{1,2},1)+0)+{0,1},MID(D3,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(D3,{1,2},1)+0,MID(D3,{1,2},1)+0))))
I4=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(D4,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(D4,{1,2},1)+0)+{0,1},MID(D4,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(D4,{1,2},1)+0,MID(D4,{1,2},1)+0))))
J1=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(E1,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(E1,{1,2},1)+0)+{0,1},MID(E1,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(E1,{1,2},1)+0,MID(E1,{1,2},1)+0))))
J2=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(E2,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(E2,{1,2},1)+0)+{0,1},MID(E2,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(E2,{1,2},1)+0,MID(E2,{1,2},1)+0))))
J3=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(E3,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(E3,{1,2},1)+0)+{0,1},MID(E3,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(E3,{1,2},1)+0,MID(E3,{1,2},1)+0))))
J4=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(E4,{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(E4,{1,2},1)+0)+{0,1},MID(E4,{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(E4,{1,2},1)+0,MID(E4,{1,2},1)+0))))
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,594
Office Version
2019
Platform
Windows
How are you storing the values in A1, A4 & B4 to show the leading zero in cell? Your formula works fine for me with the methods I've tried, formatting the cells as text or '02 in the cell.
 

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,860
How are you storing the values in A1, A4 & B4 to show the leading zero in cell? Your formula works fine for me with the methods I've tried, formatting the cells as text or '02 in the cell.
Formatted the cells as 00, so the values from 1-9 show as 01,02,09. The workbook has 376,299 rows with such values.
 

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,860
Maybe

http://www.mrexcel.com/forum/showpost.php?p=2291656&postcount=4

=IF(OR(AND(ISNUMBER(MATCH({0,9},MID(TEXT(A1,"00"),{1,2},1)+0,0))),AND(ISNUMBER(MATCH(MIN(MID(TEXT(A1,"00"),{1,2},1)+0)+{0,1},MID(TEXT(A1,"00"),{1,2},1)+0,0)))),"C",INDEX({"S","D"},MAX(FREQUENCY(MID(TEXT(A1,"00"),{1,2},1)+0,MID(TEXT(A1,"00"),{1,2},1)+0))))

Thank you, I was entering the TEXT(A1,"00") in the wrong spot, thank you very much!!
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,594
Office Version
2019
Platform
Windows
What are the criteria for the formula, is there a thread on it's creation?

I thought I had an alternative that is much shorter, but a couple of results didn't match yours.
 

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,860
What are the criteria for the formula, is there a thread on it's creation?

I thought I had an alternative that is much shorter, but a couple of results didn't match yours.

The formula works like this, any 2-digit value that is consecutive( 12,09,01) returns a "C". Any 2-digit value that is a double digit value(11,22,33) returns a (D). All other 2-digit values will be an (S).

There was a thread with this formula, but I can't find it.
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,594
Office Version
2019
Platform
Windows
So I was thinking on the right lines, I started with

=IF(ABS(INT(A1/10)-MOD(A1,10))=1,"C",IF(INT(A1/10)=MOD(A1,10),"D","S"))

resulting in "C" for 09 and 90, which technically is correct as 9 and 0 are not consecutive.

There are several ways to use 0 as a substitute for 10 in the consecutive sequence,

=IF(ISNUMBER(MATCH(ABS(INT(A1/10)-MOD(A1,10)),{1,9},0)),"C",IF(INT(A1/10)=MOD(A1,10),"D","S"))

looks fairly tidy compared to the others I've tried, and it matches your results (tested 00 through to 99).
 

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,860
So I was thinking on the right lines, I started with

=IF(ABS(INT(A1/10)-MOD(A1,10))=1,"C",IF(INT(A1/10)=MOD(A1,10),"D","S"))

resulting in "C" for 09 and 90, which technically is correct as 9 and 0 are not consecutive.

There are several ways to use 0 as a substitute for 10 in the consecutive sequence,

=IF(ISNUMBER(MATCH(ABS(INT(A1/10)-MOD(A1,10)),{1,9},0)),"C",IF(INT(A1/10)=MOD(A1,10),"D","S"))

looks fairly tidy compared to the others I've tried, and it matches your results (tested 00 through to 99).
Fantastic, very nicely done, appreciate it!!!
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,594
Office Version
2019
Platform
Windows
Not sure which of the various formula will be most efficient with the size of your data set, but a couple more for you to try.

=LOOKUP(ABS(INT(A1/10)-MOD(A1,10)),{0,1,2,9},{"D","C","S","C"})

=INDEX({"D","C","S","C"},MATCH(ABS(INT(A1/10)-MOD(A1,10)),{0,1,2,9},1))


I've only tested for values up to 99, not sure how results would compare with anything above that if there is possibility of such values in your data.
 
Last edited:

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,939
Messages
5,508,241
Members
408,670
Latest member
lhmwnrexcel

This Week's Hot Topics

Top