Macro to convert text to numbers

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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