VBA To Convert Text To Numbers

passmaster16

New Member
Joined
Apr 10, 2009
Messages
16
Hi,

I pull data into Excel 2007 from a SharePoint query. The data is pulled over into Excel in the form of a table. I would like to convert the data in columns C through I from text to numeric so that I can use the AVERAGE forumula to calculate averages for each row. I would like to be able to do this through VBA as I will also automate adding and population of the averaged column. The only problem I see is that this data is dynamic. Each month I clear the spreadsheet and run the query to grab the latest data so I need to be able to select the data from a dynamic range and convert it to numbers. Any ideas on how I can accomplish this with VBA?

Thanks in advance!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try using Text-To-Columns on those columns. Highlight a column, Data>Text to Columns, then click Finish.
 

jmthompson

Well-known Member
Joined
Mar 31, 2008
Messages
966
Find a column that will always be populated, no blanks, until the end of your data, then update the lastRow line in this code with your column. I've used column A here. I also assumed you have a header in row 1, if not, update the For each range to C1:I...

Code:
Sub Convert()
Dim c As Range
Dim lastRow As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("C2:I" & lastRow)
    If c <> "" Then
    c = 1 * c.Value
    End If
Next c

End Sub
 

Forum statistics

Threads
1,141,849
Messages
5,708,973
Members
421,602
Latest member
jkpce1880

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