Consulting

Results 1 to 5 of 5

Thread: extract the data from a string of data

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    10
    Location

    extract the data from a string of data

    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!

  2. #2
    [vba]Range("A1:A4") = Application.Transpose(Split("apple,banana,orange,melon", ","))[/vba]
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    VBAX Regular
    Joined
    Dec 2008
    Posts
    10
    Location
    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!)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim ary As Variant

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

    Range("A1").Resize(UBound(ary, 1) - LBound(ary, 1) + 1) = Application.Transpose(ary)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Dec 2008
    Posts
    10
    Location
    Thanks xld !
    This forum is really helpful !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •