Consulting

Results 1 to 9 of 9

Thread: Looping through cells (contents of cell seperated by commas) and performing vlookups

  1. #1
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    4
    Location

    Looping through cells (contents of cell seperated by commas) and performing vlookups

    This is confusing and I can't figure out how to make it work.

    I have cells that have numbers separated by commas.

    e.g., A1: "1,2,3,4"

    I want to separate those numbers out and perform a vlookup on each number and concatenate the results into one cell.

    So in another tab it might have

    1|sentence1
    2|sentence2
    3|sentence3
    4|sentence4

    I need to loop through Cell A1-A50 (or whatever) and read out 1,2,3,4 and do vlookups on the other tab and make a concatenation of sentence1sentence2sentence3 into one cell.

    I'm failing hard at making this work. Any help is greatly appreciated.

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Austin

    Can you post a sample copy workbook & where you want the data to be?

  3. #3
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    4
    Location
    My computer decided to bsod... So I'm posting from cell phone. Let's seeif I can make sample from my phone...

  4. #4
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    4
    Location
    It won't let me select a file from my phone but here is a link to public drop box.

    httpxx//db.tt/a82qegtQ replace xx with a colon

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    That link is not found
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    VBAX Newbie
    Joined
    Oct 2011
    Posts
    4
    Location
    Hey Aussie.. that link works fine. However, I wasn't able to post a normal link because of the forum restrictions (under 5 posts).

    I'm attaching it here again.. because my computer is working again. It is now attached to this post.

    THANKS!
    Attached Files Attached Files

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Is there any reason why we can't separate the values into helper columns?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    quite difficult with worksheet formulae, but a udf can do it:
    [vba]Public Function beuhh(stuff)
    xx = Split(stuff, ",")
    For Each thing In xx
    yy = Application.VLookup(CLng(Application.Trim(thing)), Sheets("data").Range("A:B"), 2, False)
    If IsError(yy) Then beuhh = beuhh & "----" Else beuhh = beuhh & yy
    Next thing
    End Function
    [/vba] Not very efficient, but does the job.
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  9. #9
    Hmm, this looks like it works. Let me try it on the real set of data and see what happens! Thanks so much.

Posting Permissions

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