Macro to add 0 to a cell containing numbers in Text format

bits32

New Member
Joined
Apr 5, 2011
Messages
2
Hi guys. i would like to seek assistance regarding macro.
- user to select the cell / range of cells containing numbers
60009
47607
47609
47615

- macro required to do the following:
1) Add 0 to each number
60009 --> 060009
47607 --> 047607
47609 --> 047609
47615 --> 047615

2) Align text to Right

that's all for now. thanks and best regards.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try

Code:
Sub AddZero()
Dim c As Range
For Each c In Selection
    With c
        .NumberFormat = "@"
        .Value = "0" & CStr(.Value)
        .HorizontalAlignment = xlRight
    End With
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,882
Members
452,948
Latest member
Dupuhini

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