+ Reply to Thread
Results 1 to 10 of 10

Loop through rows and return matching columns

  1. #1
    Registered User
    Join Date
    05-30-2008
    Posts
    64

    Loop through rows and return matching columns

    I have a worksheet with 2 columns. The first column contains names and the second column contains numbers associated with the name.

    How can I specify a name, go through the sheet to find all the occurances of that name and then paste all the numbers associated with that name in another worksheet in a set position.

    Thanks in advance

  2. #2
    Valued Forum Contributor Rahul Nagar's Avatar
    Join Date
    09-18-2008
    Location
    nasik
    MS-Off Ver
    Excel 2003
    Posts
    465
    Hello Ezzy85,

    Try "VLOOKUP" formula.

    In case you need any further assistance,please attach the file and i will do the need full.
    __________________
    Regards
    Rahul Nagar
    Founder of www.myshortcutkeys.com.


    If you get the answer of your questions then please click EDIT in your original post then click on GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.

  3. #3
    Registered User
    Join Date
    05-30-2008
    Posts
    64
    Vlookup only returns the first occurance. How can I handle it if there are 3 occurances, for example?

  4. #4
    Valued Forum Contributor Rahul Nagar's Avatar
    Join Date
    09-18-2008
    Location
    nasik
    MS-Off Ver
    Excel 2003
    Posts
    465
    can you please attach a sample file for more details?

  5. #5
    Registered User
    Join Date
    05-30-2008
    Posts
    64
    Here is a sample. The data is in the "data" sheet. I enter a name in "output" and it searches the data for that name and returns all the numbers associated with it in the "output" sheet.
    Thanks
    Attached Files Attached Files
    Last edited by ezzy85; 01-09-2009 at 02:01 AM.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello ezzy85,

    I have added the macro below to the attached workbook. This will find all occurrences of the name in cell "B1" of the "Output" sheet and copy the data for that name back to the "Output" sheet starting at cell "A4". The macro runs automatically when the user enters a name into cell "B1" on the "Output" sheet. If the name isn't found, a message box alerts the user.

    Macro Code
    Please Login or Register  to view this content.
    Worksheet Change Event Code
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-30-2008
    Posts
    64
    thats great! thanks so much

  8. #8
    Registered User
    Join Date
    05-30-2008
    Posts
    64
    hi again.
    I just realised that the code above is for a static data range. I am trying to change this line:

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    but that returns the value of the cell. How can I get it to return the range?
    thanks

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello ezzy85,

    Change that line of code to this...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  10. #10
    Registered User
    Join Date
    05-30-2008
    Posts
    64
    thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1