VBA Question - Convert Text to Numbers

rollnation2

New Member
Joined
Mar 18, 2021
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
I need to convert a few columns of raw data from text to numbers.
Using the following code works perfectly on column A. I need to perform the same conversion on columns D and S.
How do I modify the following VBA to convert column D and S?

Sub ConvertTextToNumber()
Set Rng = ThisWorkbook.Sheets("Sheet1").Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
With Rng
.NumberFormat = "General"
.Value = .Value
End With
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi & welcome to MrExcel.
Just repeat the code for the other two columns.
 
Upvote 0
Hi & welcome to MrExcel.
Just repeat the code for the other two columns.
Thanks I figured it out, silly question... I used this code

Sub ConvertTextToNumber()
Set Rng = ThisWorkbook.Sheets("Sheet1").Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
With Rng
.NumberFormat = "General"
.Value = .Value

End With

Set Rng = ThisWorkbook.Sheets("Sheet1").Range("D2:D" & Cells(Rows.Count, 1).End(xlUp).Row)
With Rng
.NumberFormat = "General"
.Value = .Value

End With

Set Rng = ThisWorkbook.Sheets("Sheet1").Range("S2:S" & Cells(Rows.Count, 1).End(xlUp).Row)
With Rng
.NumberFormat = "General"
.Value = .Value

End With

End Sub
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
Follow up question - this worked for me last week. I am trying to run the VBA from my personal macro workbook on another open workbook. It runs but does not work on the workbook I have open.
Any thoughts on why the VBA would not be working from my personal macro workbook on another open workbook?
 
Upvote 0
You need to change ThisWorkbook to ActiveWorkbook
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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