VBA remove the leading apostrophes and format

Bonz

Board Regular
Joined
Dec 10, 2007
Messages
149
Morning All,

I would like to remove the leading apostrophes from numbers stored as text in column A and preserve the leading zeros by formatting the value. The below procedure works if I run it twice but after the first run all it seems to do is to cause Excel to show the green tick mark for the cells error message and I’m not sure why?

Thanks in advance for any help!

Code:
Sub DeathToApostrophe()
    Dim s As Range
 
    Application.ScreenUpdating = False
    
    For Each s In ActiveSheet.Range("A2:A100")
        
        If s.HasFormula = False Then
             'Gets text and rewrites to same cell without   the apostrophe.
              s.Value = Format(s.Value, "000000")
            
        End If
        
    Next s
     
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,214,784
Messages
6,121,538
Members
449,038
Latest member
Guest1337

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