Number stored as text changed with "Convert to number" in VB

Ed Mah

New Member
Joined
Dec 13, 2003
Messages
26
Hi. So I'm downloading data from an external application into Excel. The problem is a lot of the data is 'Number stored as text'.

Using VB, how can I 'Convert to number'. I have hundreds of instances of this problem so manual corrections are impractical.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You can use Text to Columns on each of the columns to convert those "numbers entered as text" to "numbers".

The steps manual are:
1. Go to the Data menu
2. Select "Text to Columns"
3. Click "Finish"

But you could use the Macro Recorder to record these steps, and then edit the code to make it more dynamic.

You can only do "Text to Columns" on one column at a time, but could automate looping through multiple columns pretty easy with VBA.

An alternative trick may be to temporarily save the file as a CSV, then close it.
Then open the CSV in Excel and save it as an Excel file.
That should convert those values. However, it could potentially convert other values too, depending on what kind of data you have.
 
Upvote 0
Solution
Does this do it?

VBA Code:
Sub convert2number()

  Dim oCell As Range

  For Each oCell In ActiveSheet.UsedRange
    If IsNumeric(oCell) Then oCell = oCell.Value
  Next

End Sub
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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