Convert text into number

MGHT

New Member
Joined
Feb 18, 2008
Messages
22
Hi all, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
Hope you can help me cus i been everywhere and tried everything already.<o:p></o:p>
<o:p></o:p>
i need to convert all the numbers in a sheet from text to number format so it would do the calculations. <o:p></o:p>
<o:p></o:p>
however not all the columns are supposed to be formatted as numbers so i added a loop to identify which ones should be formatted as number. <o:p></o:p>
<o:p></o:p>
But then on such columns i used the following code to convert text to number: <o:p></o:p>
<o:p></o:p>
Code:
<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]Sub ConvertText2Num()<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]For Each xCell In Selection
   xCell.Value = CDec(xCell.Value)
Next xCell<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]     <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]End Sub<o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana] <o:p></o:p>[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]
<o:p></o:p>

<o:p></o:p>
It works great except i need it to convert the whole column except the first line cus tht one is the header. <o:p></o:p>
And secondly it gives me an error if there are any cells that do have number formatting and does not continue formatting the other cells that do not have the number formatting. <o:p></o:p>
<o:p></o:p>
Any advice to help me reach my objective would be greatly appreciated. <o:p></o:p>
<o:p></o:p>
Thank you in advance, <o:p></o:p>
<o:p></o:p>
Mayra<o:p></o:p>
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Perhaps (if I've understood):

Code:
Sub ConvertText2Num()
Dim rngArea As Range
With Selection
    .NumberFormat = "General"
    For Each rngArea In .Areas
        rngArea.Value = rngArea.Value
    Next rngArea
End With
End Sub

(change the NumberFormat as per requirements)
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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