Reformatting Text to Number

LittleMissRedK

New Member
Joined
Jul 14, 2012
Messages
1
I need to go through all the cells in a sheet and check to see if they are numbers formatted as text and then reformat them as numbers if they are. Someone suggested this:

Sub Macro1()
For Each C In UsedRange.Cells
If IsNumeric(C) Then
C.Value = Val(C)
End If
Next
End Sub

But it doesn't run. Suggestions?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello

Welcome to MrExcel.

UsedRange needs to work on say, ActiveSheet, or another valid worksheet reference.

I would try:

Code:
Sub Macro1()    For Each C In ActiveSheet.UsedRange.SpecialCells(2, 2)
        C.Value = Val(C)
    Next
End Sub

PS: Please use code tags when you paste VBA code on the forum.
To add code tags, you can click the # icon and paste your code.


Or, a manual approach is, to type in your post:


Code:
then paste your code, and lastly, type:


['/code]


WITHOUT the single quotation mark ' in front of the /


Thanks for the consideration.
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,793
Members
451,589
Latest member
Harold14

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