How do I add leading zeroes in this example?

Sampoline

New Member
Joined
Dec 2, 2020
Messages
24
Office Version
  1. 2013
Platform
  1. Windows
I want to take the original naming in the image below and turn it into the required naming format. This includes substituting "/" with "-" and then adding a leading zero to sequence number at the end of the number.

Using the 1st column, I used a simple Substitute formula to change the "/" to a "-" in the 2nd column. But I can't figure out how to add the leading zero like shown in the 3rd column. And then to make the substitution and leading zero addition work together in a single formula possibly?

1606890831922.png
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Use this formula at cell C2 for source cell B2:
Excel Formula:
=SUBSTITUTE(B2,RIGHT(B2,SEARCH("-",B2)-1),0&RIGHT(B2,SEARCH("-",B2)-1))
 
Upvote 0
I see the previous formula have problems. please use this:
Excel Formula:
=SUBSTITUTE(B2,RIGHT(B2,LEN(B2)-SEARCH("#",SUBSTITUTE(B2,"-","#",LEN(B2)-LEN(SUBSTITUTE(B2,"-",""))))),0&RIGHT(B2,LEN(B2)-SEARCH("#",SUBSTITUTE(B2,"-","#",LEN(B2)-LEN(SUBSTITUTE(B2,"-",""))))))
 
Upvote 0
Welcome to MrExcel Message Board.
Sorry I don't noticed at Previous Posts.

Or You can Use only this for Column A , Start at A2:
Excel Formula:
=SUBSTITUTE(LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/",""))))))),"/","-")&0&RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))
 
Upvote 0
Try
=LEFT(A2,8)&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-8),"00"))), "0" & RIGHT(A2,LEN(A2)-8),TEXT(RIGHT(A2,LEN(A2)-8),"00"))
 
Upvote 0
Welcome to MrExcel Message Board.
Sorry I don't noticed at Previous Posts.

Or You can Use only this for Column A , Start at A2:
Excel Formula:
=SUBSTITUTE(LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/",""))))))),"/","-")&0&RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))
Hi Maabadi, sorry for the late response. Was away for a day. This formula ALMOST works. Only thing is, I want the leading zero only for a single digit number, not double digit.

For e.g. 'A-DQ-A1-01' but NOT 'A-DQ-A1-010'; it should be 'A-DQ-A1-10'
 
Upvote 0
Sampoline, If you have fixed length before last slash "/" , then use Zot Formula, Otherwise Use this:

Excel Formula:
=LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))), "0" & RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))
 
Upvote 0
Sampoline, If you have fixed length before last slash "/" , then use Zot Formula, Otherwise Use this:

Excel Formula:
=LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))), "0" & RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))
Zot's formula doesn't substitute "/" for "-"

And the one you posted also does not either. I need to substitute the forward slash with the hyphen and also only add the leading zero to single-digit numbers.
 
Upvote 0
Sorry I forgot to add substitiue function:
1. this is for Zot function:
Excel Formula:
=SUBSTITUTE(LEFT(A2,8)&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-8),"00"))), "0" & RIGHT(A2,LEN(A2)-8),TEXT(RIGHT(A2,LEN(A2)-8),"00")),"/","-")
2. this is for my Function:
Excel Formula:
=SUBSTITUTE(LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))), "0" & RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00")),"/","-")
 
Upvote 0
Solution
Sorry I forgot to add substitiue function:
1. this is for Zot function:
Excel Formula:
=SUBSTITUTE(LEFT(A2,8)&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-8),"00"))), "0" & RIGHT(A2,LEN(A2)-8),TEXT(RIGHT(A2,LEN(A2)-8),"00")),"/","-")
2. this is for my Function:
Excel Formula:
=SUBSTITUTE(LEFT(A2,LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))&IF(ISERROR(VALUE(TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00"))), "0" & RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),TEXT(RIGHT(A2,LEN(A2)-(LEN(A2)-LEN(RIGHT(A2,LEN(A2)-SEARCH("#",SUBSTITUTE(A2,"/","#",LEN(A2)-LEN(SUBSTITUTE(A2,"/","")))))))),"00")),"/","-")
No need to apologise! Thanks a lot for being patient to answer my questions. You're solution worked out for me.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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