+ Reply to Thread
Results 1 to 10 of 10

For each cell in one column search for match in entire differnet coloumn

  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Unhappy For each cell in one column search for match in entire differnet coloumn

    I have a workbook with two sheets, I'm trying to figure out how to make it take use the value from each cell in column E of sheet 2 and search all of column A in sheet one, then if a matching value is found run a different function... I've tried a number of methods I have found and something goes really wrong every time I try and make them work.... Any suggestions?

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: For each cell in one column search for match in entire differnet coloumn

    You have this in the VBA forum, but I think you can probably do this with a simple vlookup or index/match?

    If you upload a sample workbook, showing your data, I will take a look at it for you
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Re: For each cell in one column search for match in entire differnet coloumn

    I am trying to run it as part of a more complex VBA code, but I'm VERY new to this and have been stuck on this part for a while.... In the uploaded file the columns should be as described, sheet 2 is called Summary and Sheet1 is just that... the values I am trying to compare are invoice numbers. Thanks for any help!
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: For each cell in one column search for match in entire differnet coloumn

    Maybe something like this:

    Please Login or Register  to view this content.
    Last edited by AlvaroSiza; 03-25-2013 at 04:25 PM. Reason: Touch up
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  5. #5
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Re: For each cell in one column search for match in entire differnet coloumn

    How would I close the For loop in your example?

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: For each cell in one column search for match in entire differnet coloumn

    It closes itself via
    Please Login or Register  to view this content.
    when (and where) i equals the upper bound (or count) of the array, which represents the data encompassing Range("E2:67") in your example.

  7. #7
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Re: For each cell in one column search for match in entire differnet coloumn

    Thanks, for some reason when I viewed it previously your code ended at this line:

    '...do whatever you wanted to do once the match was found


    Thank you, I'll let you know how it goes!

  8. #8
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Re: For each cell in one column search for match in entire differnet coloumn

    I'm getting a Type Mismatch for this line

    Please Login or Register  to view this content.
    Is this because sArr is a string and rngSource is a range?

  9. #9
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: For each cell in one column search for match in entire differnet coloumn

    Possibly. I threw this together pretty quick.

    If sArr = rngSource doesn't work (without the .Value), change sArr() as String to sArr() as Variant when dimensioning.

  10. #10
    Registered User
    Join Date
    02-11-2013
    Location
    eugene, or
    MS-Off Ver
    Excel 2011
    Posts
    74

    Re: For each cell in one column search for match in entire differnet coloumn

    Hmmm, I tried both... removing the .Value yields the same error and the Variant yields an error 9 subscript out of range for this block

    Please Login or Register  to view this content.

+ 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