I want to remove all the leading 0's from the numbers in this column, without affecting the rows that start with a letter.
-
4I think you may have forgotten to include in your question what you have tried and what aspect of it isn't working. – Ambie Jul 27 '16 at 15:06
5 Answers
For a non-VBA solution, you can highlight the entire row and go to Data>Text-To-Columns and then hit "Finish". Numbers will be converted to numeric format and strings will remain untouched.
For a VBA solution, you could iterate through the cells:
For each rngCell in Sheet1.Columns("A").Cells
Next rngCell
And within that iteration, use isnumeric()
to test before replacing
If isnumeric(rngCell.value) Then rngCell.value = rngCell.value + 0
Or something along those lines. You could also record that text-to-columns bit and just sub out your column's range in the VBA. Depending on how much control you need over your data transformation.

- 46,980
- 4
- 38
- 63
-
1... and of course the number format shouldn't be something like this: `rngCell.NumberFormat = "0000000000"` ;) – Ralph Jul 27 '16 at 15:20
Another Non VBA Solution... (Simplest of all)
- Highlight the data
- You will see an Exclamation Mark next to your data as shown in screenshot. Click on it
- Click on
Convert To number
and you are done :)
Result

- 147,039
- 17
- 206
- 250
you can use this formula. my formula source data starts from B3.
=REPLACE(B3,1,FIND(LEFT(SUBSTITUTE(B3,0,"")),B3)-1,"")

- 2,665
- 1
- 13
- 29
Try to convert the cell to a number and then back to string - if it fails it already was a string. vba convert string to int if string is a number
Edit:
Try to solve it with an regex:
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "^0*"
End With
If regEx.Test(strInput) Then
strInput = regEx.Replace(strInput, "")
End If
Source: How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

- 31
- 5
-
This won't fulfill the requirement exactly. Some start with zeros but still have chars in them. – Mike Cheel Jul 27 '16 at 15:14
-
I just saw that. then your could use the regex `^0*` and replace with an empty string. – user3421658 Jul 27 '16 at 15:26
You could do it with a formular with or without VBA:
=IF(ISNUMBER(Value(A1));Value(A1);A1)

- 16
- 4
-
Yes, of course i have tested it, works perfectly. Didn't it work for you? – thentt Jul 28 '16 at 10:45
-
I am working on Excel 2016. As per my understanding The ISNUMERIC function can only be used in VBA code in Microsoft Excel whereas you have mentioned that one can do it with a formula with or without VBA. Another Worksheetfunction ISNUMBER works fine for me in the formula. – skkakkar Jul 28 '16 at 13:33
-
Yeah, you are right. Thank you. I had to test it in an excel with an different language package. Lost in Translation. – thentt Aug 02 '16 at 14:38