+ Reply to Thread
Results 1 to 13 of 13

Search for matching cells in table

  1. #1
    Registered User
    Join Date
    11-15-2013
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Question Search for matching cells in table

    Hello!

    I recently solved a problem I had with copying and pasting cells, but now I have a problem with searching for cells with values in them (some are numbers, some include letters). But "dim"ing them as strings or variants doesn't work in this case for some reason. Here are some examples I've tried:

    Please Login or Register  to view this content.
    If anyone could share some knowledge on a way to get around this problem. Some of the values for son would be 'B00098' or 'N03123' etc. as well as '342123'.
    Last edited by neek13; 01-22-2014 at 05:27 PM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Change this line

    Please Login or Register  to view this content.
    INTO
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Or direct cell reference.

    Please Login or Register  to view this content.
    I suspect, you may need to change the AND into OR

  4. #4
    Registered User
    Join Date
    11-15-2013
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Search for matching cells in table

    AB33, thanks for your help.

    I removed the "as string" and "as long" and that didn't seem to change anything except remove the 'type mismatch error'; now the code runs for a few seconds then stops without anything having happened.

    I also replaced the variables with direct cell references and that didn't change anything either.

    What do you mean by changing AND into OR? The search I'm doing needs the AND because all three column values have to be true so that the row can be copied.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Neek13,
    Okay, do you have exact match in sheet column B with the other columns? What sort of data do you have in column B?
    It would be easier to solve it, even improve the code if you could attach the sample you are working on.

  6. #6
    Registered User
    Join Date
    11-15-2013
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Search for matching cells in table

    Yes, the match is exact.

    Sure, here's a sample workbook. The macro is in Module 1.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    neek13,
    I have not looked in details, but your code looks correct. There are no obvious errors, but I am wondering if there is a match in a single row (All 3 of them),hence there is no error on the code, neither there is a match.

    The way I tested it this way. Put each if statement on a separate line and see if all could match. The code finds for example, the first 6216. The code will not find 6216, until row 68, so the code will return nothing until that line. From there, it tests B07582 and the so on.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    The first cell with value B07582 is found in 6580, which means the code will be false until that row.

  9. #9
    Registered User
    Join Date
    11-15-2013
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Search for matching cells in table

    Yes.

    I tried running it with the three if statements but still nothing happens. There are several rows that have all '6216' 'B07582' and '180'...

    This worked perfectly fine when I was looking for solely numerical values, but it basically doesn't find it now that there's text involved.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Okay! give me a couple of minutes for testing.

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Found the problem; you had spaces, so I used trim.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-15-2013
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Search for matching cells in table

    That's awesome! I never would've noticed that. The table is from a query that gets updated so I never would've thought to check it.

    Thank you so much!

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Search for matching cells in table

    Neek13,
    Data imported from other systems and website have lots of unseen and dirty characters. You should first clean the data before using the data in excel. One way would be to copy and paste VALUES ONLY. Delete the imported data from your book and work on the clean one.

    You are welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Search to find matching cells and copy/transpose adjacent data to original sheet?
    By thump4r in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-12-2009, 09:20 PM
  2. search for matching cells and combine results
    By meacho in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2007, 08:25 AM
  3. [SOLVED] Search for multiple cells with a row for matching criteria, then sum up certain column
    By drdavidge in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-08-2006, 01:15 PM
  4. Replies: 0
    Last Post: 08-08-2006, 10:35 AM
  5. Search & match more than one worksheet and matching cells.
    By Monica in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-30-2006, 05:55 PM

Tags for this Thread

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