PDA

View Full Version : extract the data from a string of data



garyc
12-15-2008, 12:30 AM
can we get the data from a string of data with marks to separate the useful items

For exampe,

apple, banana, orange, melon,......

-->

turn into a spreadsheet in a column

Cell
A1: apple
A2: banana
A3: orange
A4: melon

Can we do this with VBA in excel ????????????????????
I just know I can use len() and left() and right() and find()
but I just can do the above process when the string just contain 2 items.

Thanks!

JimmyTheHand
12-15-2008, 12:44 AM
Range("A1:A4") = Application.Transpose(Split("apple,banana,orange,melon", ","))

garyc
12-15-2008, 03:54 AM
Thanks for your Answer !JummyTheHand!
However, I still have some problem. What if the string is really long, and you don't know how many items inside the string. How to tackle this problem? How to set the range at the left hand side.

(By the way, This forum is really awesome. This is my first day here. The problem posted are quickly solved. I guess this forum is full of smart guys who good at VBA!:thumb)

Bob Phillips
12-15-2008, 04:03 AM
Dim ary As Variant

ary = Split("apple,banana,orange,melon", ",")

Range("A1").Resize(UBound(ary, 1) - LBound(ary, 1) + 1) = Application.Transpose(ary)

garyc
12-15-2008, 04:53 AM
Thanks xld !
This forum is really helpful !!!:rotlaugh: