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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try using Text-To-Columns on those columns. Highlight a column, Data>Text to Columns, then click Finish.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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