VBA to convert text to a number

windsurfit

Board Regular
Joined
Mar 27, 2003
Messages
228
My sheet contains many cells (also entire rows and columns) that have data sorted from another sheet. Many results have "text" values that I need converted to numeric.

I want to convert more than one cell at a time (as is done under error checking) using a Macro. Ideally the whole sheet or at least a column at a time.

Hopefully this is fairly simple.

Thx
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
My sheet contains many cells (also entire rows and columns) that have data sorted from another sheet. Many results have "text" values that I need converted to numeric.

I want to convert more than one cell at a time (as is done under error checking) using a Macro. Ideally the whole sheet or at least a column at a time.
Give this a try...
Code:
Sub ConvertTextNumbersToRealNumbers()
  With ActiveSheet.UsedRange
    .NumberFormat = "General"
    .Value = .Value
  End With
End Sub
 
Upvote 0

windsurfit

Board Regular
Joined
Mar 27, 2003
Messages
228
Hi Rick,

Thanks- it seems to work..will try the upload to my internal software and see if it chokes...

Your the best.
 
Upvote 0

windsurfit

Board Regular
Joined
Mar 27, 2003
Messages
228
Hey,

OK- after running tests it appears that I don't want the whole sheet converted just specific columns of data..
In this case columns: C:K (only).

Hopefully this is a simple modification to the above.

Thx again..
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,154
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
OK- after running tests it appears that I don't want the whole sheet converted just specific columns of data..
In this case columns: C:K (only).
This should work...
Code:
Sub ConvertTextNumbersToRealNumbers()
  With Intersect(ActiveSheet.UsedRange, Columns("C:K"))
    .NumberFormat = "General"
    .Value = .Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,195,934
Messages
6,012,385
Members
441,694
Latest member
Elvin A

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
Top