Splitting out text in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone. I have a cell that contains multiple values, separated by commas. What I would like to do is split out the text data based on the comma. So let's say that my cell contains the following: Red, Blu

This is my code
Text_Array = Split(CurrentCell,Chr(44)
MsgBox Text_Array(0
MsgBox Text_Array(1

So I would expect to see two message boxes, the first one to say Red, the second to say Blue. But when I do this, I get an error message that says "Subscript out of range". Is there something that I am doing wrong

Thanks
Chris
 
Replace "CurrentCell" with "ActiveCell".

-Brad
-----Original Message-----
Hi everyone. I have a cell that contains multiple values,
separated by commas. What I would like to do is split out
the text data based on the comma. So let's say that my
cell contains the following: Red, Blue
This is my code:
Text_Array = Split(CurrentCell,Chr(44))
MsgBox Text_Array(0)
MsgBox Text_Array(1)

So I would expect to see two message boxes, the first one
to say Red, the second to say Blue. But when I do this, I
get an error message that says "Subscript out of range".
Is there something that I am doing wrong?
 
I don't know what CurrentCell is but this works

Sub a()
Dim Text_Array As Variant
Text_Array = Split(ActiveCell.Value, Chr(44))
MsgBox Text_Array(0)
MsgBox Text_Array(1)
End Sub
 
Back
Top