Macro to convert text to numbers

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have numbers that when imported appear as text in Col F

I have tried to write code to convert these into numbers, but the text for eg '1.00. '3.00 etc will not convert to 1.00, 3.00 etc


Book1
A
1Stock Holding
21.00
31.00
41.00
51.00
61.00
71.00
82.00
93.00
101.00
111.00
122.00
131.00
Sheet3



Code:
 Sub convertTextToNumbers ()
 with Sheets(3)
. Range("F:F")
.NumberFormat = "General"
.Value = .Value
End With

End Sub


it would be appreciated if someone could assist me
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try:

Code:
Sub convertTextToNumbers()
    With Sheets(3).Range("F:F")
        .NumberFormat = "General"
        .Value = .Value
    End With
End Sub
 
Last edited:
Upvote 0
Try...

Code:
Sub Howard()

    Columns("F:F").TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
                                 TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, FieldInfo _
                                                                                             :=Array(1, 1), TrailingMinusNumbers:=True
End Sub

Please make sure that you have data/headers in F1. Obviously format your cell accordingly after the conversion.
 
Last edited:
Upvote 0
This may work - depends on from where the data is imported.
Code:
Sub ConvertIt()
Dim R As Range, Vin As Variant, Vout As Variant, i As Long
Set R = Range("F1:F" & Cells(Rows.Count, "F").End(xlUp).Row)
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
Application.ScreenUpdating = False
For i = 1 To UBound(Vin, 1)
    Vout(i, 1) = Val(Vin(i, 1))
Next i
With Range("A1:A" & UBound(Vin, 1))
    .Value = Vout
    .NumberFormat = "0.00"
End With
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Thanks for the help guys. Code works perfectly
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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