Manipulating a comma delimited String

S

Steve Roberts

I have a variable that contains a string with up to 4 commas in it. I
need to split out each part of the sting into separate variables. I am not
sure where to begin. I have done this with just 1 comma but the logic I used
for that doesn't seem to apply here.

strTest = test1,test2,test3,test4,test5

Variable1 = test1
Variable2 = test2
Variable3 = test3
Variable4 = test4
Variable5 = test5

Thanks in advance for any suggestions you may have.

Steve
 
K

Ken Snell

Dim varSplitArray As Variant
varSplitArray = Split(strTest, ",")
Variable1 = varSplitArray(0)
Variable2 = varSplitArray(1)
Variable3 = varSplitArray(2)
Variable4 = varSplitArray(3)
Variable5 = varSplitArray(4)
 
S

Steve Roberts

Thanks that did it. That is the first time I have used an array and the
split function. Very cool!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top