VBA convert text to number
Solved
fapfapfap
-
sagessedz Posted messages 4 Status Membre -
sagessedz Posted messages 4 Status Membre -
Hello,
I have a range of cells in my document where numbers are stored as text... I'd like to have some lines of VBA code to convert them to numbers so that I can use them in calculations.
Could you please help me? (Excel 2007)
Thank you in advance :)
I have a range of cells in my document where numbers are stored as text... I'd like to have some lines of VBA code to convert them to numbers so that I can use them in calculations.
Could you please help me? (Excel 2007)
Thank you in advance :)
6 réponses
Hello,
For example, to convert A1:A10 into Integers:
--
Best regards,
Franck P
For example, to convert A1:A10 into Integers:
Sub test() Dim Array(), i As Long Array = Range("A1:A10") For i = LBound(Array, 1) To UBound(Array, 1) Array(i, 1) = CInt(Array(i, 1)) 'replace CInt with CDbl if decimal numbers Next Range("A1").Resize(UBound(Array, 1), 1) = Array End Sub --
Best regards,
Franck P
The range to be transformed in my case contains 2 columns...
Can you please indicate the solution again?
Thank you again for your invaluable help!
Thanks again!!
P.S.: I can't seem to mark the topic as resolved... if a mod could take care of it for me...
Do you have any idea?
In the empty lines, you are trying to convert "nothing" into an integer. That won’t work.
Focus on your last filled line...
Another idea, perhaps there is a value other than numbers among your 30,000 lines... A letter? An #N/A error? Something else?