Need Help. Remove Leading Zeroes from Text Cells

RHONDAK72

Board Regular
Joined
Dec 26, 2007
Messages
133
I use Excel 2010. I’m trying to figure out a way to remove the leading zeroes from a text field. I want to eventually code the process in VBA.

The text field could be different number/text combinations such as the examples below. In the end, I want the following results:

01234500 would become 1234500
001234CD would become 1234CD
000123EF would become 123EF
123456CD would become 123456CD
AB012345 would become AB012345
AB0123CD would become AB0123CD
AB123456 would become AB123456

I’ve tried 2 different options and neither option below works, because it either ignores the leading zeroes or it returns an error. See the examples below.

OPTION 1: Multiply by 1 Method:

1. Enter 1 in a cell and copy it.
2. Select the cells that you wish to alter.
3. Right click and select Paste Special.
4. Choose multiply.
5. Click OK.

Results using this method:
01234500 becomes 1234500
001234CD becomes 001234CD – Leading zeroes remain. This won’t work.
123456CD becomes 123456CD
000123EF becomes 000123EF – Leading zeroes remain. This won’t work.
AB012345 becomes AB012345
AB0123CD becomes AB0123CD
AB123456 becomes AB123456

OPTION 2:

Example Formula:
=IF(LEFT(A2,1)="0",TEXT(A2*1,"#"),A2)

Results using this method:

01234500 becomes 1234500
001234CD becomes #VALUE! – This error won’t work.
123456CD becomes 123456CD
000123EF becomes #VALUE! – This error won’t work.
AB012345 becomes AB012345
AB0123CD becomes AB0123CD
AB123456 becomes AB123456

Does anyone have any ideas?
 
Last edited:
This UDF works:

Code:
Function CleanZero(MyText As String)
    CleanZero = Replace(LTrim(Replace(MyText, "0", " ")), " ", 0)
End Function
 
Upvote 0
Another option:
Excel Workbook
AB
112345001234500
2001234CD1234CD
3000123EF123EF
4123456CD123456CD
5AB012345AB012345
6AB0123CDAB0123CD
7AB123456AB123456
Sheet
 
Upvote 0

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