how to remove those first 0 in a cell

newapa

Board Regular
Joined
Sep 13, 2012
Messages
69
hi!

i wonder if ther some how i can check if the start of the string is 0 and remove it så it start with a number insted.

somthing like this

Code:
016.00123.000
006.00071.000
162.00003.000
012.00065.000
009.00012.000
224.00001.000

to 

16.00123.000
6.00071.000
162.00003.000
12.00065.000
86.00012.000
224.00001.000

thx in advance
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Assuming that your data start from A1 cell

Code:
=--LEFT(A1,FIND(".",A1)-1)&MID(A1,FIND(".",A1),255)

To Avoid error
Code:
=IFERROR(--LEFT(A1,FIND(".",A1)-1)&MID(A1,FIND(".",A1),255),A1)

Drag it down
 
Upvote 0
hi!

sorry it was bad of me. i didn't type in what i'm searching for. i'm after a macro.
thanx. for the formula. but could u help me with a macro?

thx in advance
 
Upvote 0
Try the below code

Code:
Sub RemoveLeadingZeros()
Dim LeftVal As Integer, x As Byte, ResulT As String
Dim c As Variant, CkP As Byte

CkP = MsgBox("Have you selected the Range?", _
        vbQuestion + vbYesNo + vbDefaultButton1, "Confirmation About Data Selection")

If CkP = 7 Then Exit Sub

For Each c In Selection
    x = InStr(1, c.Value, ".")
    
    If x Then
        On Error GoTo SkiPLooP
        LeftVal = Left(c.Value, x - 1)
        
        On Error GoTo 0
        ResulT = LeftVal & Mid(c.Value, x, 255)
        c.Value = ResulT
    End If
    
SkiPLooP:

Next c

End Sub
 
Upvote 0
Another couple of ways to achieve this are:

Code:
Sub DeleteLeadingZeros()
Dim reg As Object, cll
Set reg = CreateObject("VBScript.regexp")
With reg
    .Pattern = "^0{0,2}(\d{1,3})"
    For Each cll In ActiveSheet.UsedRange
        cll.Value = .Replace(cll.Value, "$1")
    Next
End With
End Sub

or

Code:
Sub DeleteLeadingZeros2()
Dim cll, temp
    For Each cll In ActiveSheet.UsedRange
        temp = Split(cll.Value, ".")
        If IsArray(temp) Then
            temp(LBound(temp)) = Str(Val(temp(LBound(temp))))
            cll.Value = Join(temp, ".")
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Sorry, stuffed up second example and ran out of edit time. Instead:

Code:
Sub DeleteLeadingZeros2()
Dim cll, temp
    For Each cll In ActiveSheet.UsedRange
        If cll.Value <> "" And InStr(cll.Value, ".") Then
            temp = Split(cll.Value, ".")
            temp(LBound(temp)) = Str(Val(temp(LBound(temp))))
            cll.Value = Join(temp, ".")
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,216
Messages
6,129,564
Members
449,516
Latest member
lukaderanged

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