Add leading 0

ekhawaja

Board Regular
Joined
Dec 16, 2018
Messages
60
Office Version
  1. 365
Hello, looking for a formula to add a leading 0 if there is no 0 at the beginning of text:
Have: Want: Formula
05MS203005MS2030
05MS203105MS2031
5MS203905MS2039
5MS204005MS2040

The length of text varies, but need a "0" if there is no "0" present initially.
thanks in advance!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How about this:
Book1
AB
105MS203005MS2030
205MS203105MS2031
35MS203905MS2039
45MS204005MS2040
Sheet2
Cell Formulas
RangeFormula
B1:B4B1=IF(--LEFT(A1,1),"0"&A1,A1)


However, if the first letter/number is not a 0 or a number, then you should use this:
Excel Formula:
=IF(LEFT(A1,1)<>"0","0"&A1,A1)


Edit: That also begs the question, could you have a value like this where you would want to add another leading 0? "0MS2050" to become "00MS2050"
 
Upvote 1
Solution
Hello, looking for a formula to add a leading 0 if there is no 0 at the beginning of text:
Have: Want: Formula
05MS203005MS2030
05MS203105MS2031
5MS203905MS2039
5MS204005MS2t

How about this:
Book1
AB
105MS203005MS2030
205MS203105MS2031
35MS203905MS2039
45MS204005MS2040
Sheet2
Cell Formulas
RangeFormula
B1:B4B1=IF(--LEFT(A1,1),"0"&A1,A1)


However, if the first letter/number is not a 0 or a number, then you should use this:
Excel Formula:
=IF(LEFT(A1,1)<>"0","0"&A1,A1)


Edit: That also begs the question, could you have a value like this where you would want to add another leading 0? "0MS2050" to become "00MS2050"
thank you so much, it works!
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

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