View Single Post
 
Old 12-23-2012, 09:03 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Convert String Array to Integer Array from a User Input?

Code:
Sub q()

Dim vInput As Variant
vInput = InputBox("", "", "9,1,3,5,6,2,4,10,7,8")

Dim arr As Variant, a As Variant
arr = Split(vInput, ",")

Debug.Print TypeName(arr) '' String()

For a = LBound(arr) To UBound(arr)
    arr(a) = CInt(arr(a)) '' to convert string to integer
    Debug.Print TypeName(arr(a)) '' String
Next a

End Sub
This is a general VBA question.
I ask it here. I code the above in Word though.

I want to use CInt() to convert each item in an array from string to integer but it fails.
How can I convert a string array to an integer array?

Thank you.
Reply With Quote