
Use a user-defined function to delete leading
zeros for specified cells
In this example, we delete all leading zeros with a user-defined
function. Insert a new worksheet and type some numbers with
leading zeros. You will need to enter an apostrophe before the first
digit and continue with zeros. Create a user-defined function as
shown below to delete those zeros.
4
To delete all leading zeros:
1. Press <Alt+F11> to open the Visual Basic Editor.
2. From the Insert menu, click Module.
3. Type the following function:
Function KillZeros(rng As Range)
Dim intS As Integer
intS = rng
While intS - Int(intS) > 0
intS = intS * 10
Wend
KillZeros = intS
End Function
4. Close ...