Trimming leading zero (0)

CripZZ23

New Member
Joined
Dec 22, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a filed with data similar to the following:

AA-01
AA-02
AA-02 (01)
AA-10
AA-10 (01)
AA-10 (12)

Essentially it is always two letters followed by a - then a number (1 or 2 digits, but possibly zero padded to the left), and optionally another 1 to 2 digits in ( ) that is also potentially zero padded to the left.

I would like to remove the leading zeros so that they look like the right column below:
AA-01 AA-1
AA-02 AA-2
AA-02 (01) AA-2 (1)
AA-10 AA-10
AA-10 (01) AA-10 (1)
AA-10 (12) AA-10 (12)

I'm struggling - any help?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Assuming your cell values are in A1:A6, you could do something like this:

Excel Formula:
=LET(cellValues,A1:A6,TRIM(TEXTSPLIT(cellValues,"-")&"-"&LET(firstNumbers,TEXTSPLIT(TEXTAFTER(cellValues,"-")," "),IF(LEFT(firstNumbers,1)="0",RIGHT(firstNumbers,1),firstNumbers))&" "&LET(lastNumbers,IFNA(TEXTAFTER(cellValues," "),""),IF(LEFT(lastNumbers,2)="(0","("&RIGHT(lastNumbers,2),lastNumbers))))

But Rorys is way easier and more efficient.
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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