Leading zero within cell string of unique identifier

RayGraham

New Member
Joined
Feb 24, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'm trying to format the result of the formula so that it includes a leading zero within the StepID. For example "101-01-01". here's the formula and a screenshot of the spreadsheet below...

=TEXT(IF(ISBLANK(A2),LEFT(I1,(SEARCH("^^",SUBSTITUTE(I1,"-","^^",LEN(I1)-LEN(SUBSTITUTE(I1,"-",""))))))&""&D2,LEFT(A2,(SEARCH("^^",SUBSTITUTE(A2,"-","^^",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))))&""&D2),"000-00-00")

LeadZero.png
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,

You didn't give any details about your data in A2, D2, and I2
This assumes D2 is either Text or Custom formatted to show leading 0 (zero)
also assumes A2 and I2 is always ###-1 or 2 ##-#

Book3.xlsx
ABCDEFGHIJ
2104-1-21103-1-1104-01-01
Sheet1020
Cell Formulas
RangeFormula
J2J2=LEFT(IF(A2="",I2,A2),4)&TEXT(MID(SUBSTITUTE(I2,"-",REPT(" ",99)),99,99),"00")&TEXT(D2,"-00")
 
Upvote 0
Solution
You're welcome, thanks for the feedback.

I noticed an inconsistency in my formula, this is the Corrected version, please use this one:

Book3.xlsx
ABCDEFGHIJ
2104-8-21103-1-1104-08-01
Sheet1020
Cell Formulas
RangeFormula
J2J2=LEFT(IF(A2="",I2,A2),4)&TEXT(MID(SUBSTITUTE(IF(A2="",I2,A2),"-",REPT(" ",99)),99,99),"00")&TEXT(D2,"-00")
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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