PDA

View Full Version : Convert list of numbers into an array



mdmackillop
08-25-2006, 02:39 PM
Is there a simple method to convert a list of numbers, returned in an Input box for example, into an array or cell reference
eg

a = "2,4,6,8"
Arr = array(a)

b = "7,5"
set r = cells(b)

OBP
08-25-2006, 02:46 PM
Do you want to do one, or both?

mdmackillop
08-25-2006, 02:49 PM
Both. I know I can do a string manipulation, but is there an alternative?

OBP
08-25-2006, 03:01 PM
Sorry, unlike range,which works fine, I can't even get the string to work with cells :banghead:

Bob Phillips
08-25-2006, 03:20 PM
Sub Malcolm()
Dim a, b, Arr

a = "2,4,6,8"
Arr = Split(a, ",")
MsgBox Arr(0)


End Sub

mdmackillop
08-25-2006, 03:34 PM
Thanks Bob,
I knew that, but never applied in that fashion!

Bob Phillips
08-26-2006, 02:08 AM
Thanks Bob,
I knew that, but never applied in that fashion!

I use that technique all the time Malcolm. Setup a global constant as a string and then array it in my initialise procedure. Very handy.

Bob Phillips
08-26-2006, 02:12 AM
Malcolm,

There is another way I should have showed you



Sub Malcolm2()
Dim ary

ary = [{"2","4","6","8"}]

End Sub


But I must admit I don't use that much, as it doesn't fell like 'real' VB to me.

mdmackillop
08-26-2006, 02:22 AM
Not a "format" I've come across, but I'll have a play with it.
Thanks