VBA Question - Convert Text to Numbers

rollnation2

New Member
Joined
Mar 18, 2021
Messages
4
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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
Just repeat the code for the other two columns.
 

rollnation2

New Member
Joined
Mar 18, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback.
 

rollnation2

New Member
Joined
Mar 18, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
You need to change ThisWorkbook to ActiveWorkbook
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,425
Messages
5,642,051
Members
417,251
Latest member
Dordrecht

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