Remove left "0" zero numbers

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
890
Hi all, i would like to write a VBA code so that to run through col. "A" and should remove the left "0" (zero) numbers but NOT any in the middle or end of the code. Below in Sch. 1. are the original data and in Sch. 2. is the expected result. Many TIA.

Sch.1.

<tbody>
[TD="class: xl63, align: right"]00004[/TD]

[TD="class: xl63, align: right"]00022[/TD]

[TD="class: xl63, align: right"]00148[/TD]

[TD="class: xl63, align: right"]01706[/TD]

[TD="class: xl63, align: right"]01836[/TD]

[TD="class: xl63, align: right"]02079[/TD]

[TD="class: xl63"]
30748

Sch.2.

<tbody>
[TD="class: xl65, align: right"]4[/TD]

[TD="class: xl65, align: right"]22[/TD]

[TD="class: xl65, align: right"]148[/TD]

[TD="class: xl65, align: right"]1706[/TD]

[TD="class: xl65, align: right"]1836[/TD]

[TD="class: xl65, align: right"]2079[/TD]

[TD="class: xl65, align: right"]30748[/TD]

</tbody>

[/TD]

</tbody>
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Code:
Sub textToNumber()

    With Columns(1)
    
        For x = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
            tempStr = Cells(x, 1)
            Cells(x, 1).Value = Val(tempStr)
        Next x
    
    
    .NumberFormat = "0_);(0)"
    
    End With




End Sub
 
Upvote 0
Hi all, i would like to write a VBA code so that to run through col. "A" and should remove the left "0" (zero) numbers but NOT any in the middle or end of the code. Below in Sch. 1. are the original data and in Sch. 2. is the expected result. Many TIA.
If the values in column A are numbers formatted as "00000" then
Code:
Sub RemoveEm_FormattedNumbers()
  Columns("A").NumberFormat = "General"
End Sub

If the values in column A are Text then
Code:
Sub RemoveEm_Text()
  With Columns("A")
    .NumberFormat = "General"
    .Value = .Value
  End With
End Sub
 
Upvote 0
Hi Neon, thank you so much for your support. The code works perfect and nicely. Hv a great day!
 
Upvote 0
Hi Peter, thanks for your support. It seemed that, the numbers are in text and so the second code adapt to my project and it works perfect. Thanks once again for your support. Hv a lovely day!
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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