+ Reply to Thread
Results 1 to 19 of 19

How to search across 2 columns for keywords from a list and copy each row to a new sheet?

  1. #1
    Registered User
    Join Date
    04-14-2012
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    8

    How to search across 2 columns for keywords from a list and copy each row to a new sheet?

    Hello Everyone,

    I've been able to find great advices numerous times before in this forum, but this is the first time I couldn't find an answer to a new problem. My apologies if this has been answered before but hopefully someone can point me in the right direction.


    I have 3 worksheets:
    1. Sheet1 is a huge Data Set with values starting from column A10 to I10. A10 to I10 is the header.
    2. Sheet2 is blank with headers on row 1.
    3. Sheet3 is a list of keywords under column A.

    My goal is create a macro that will look at each of the keywords listed in Sheet3 and search for them in Column B and Column D of Sheet1. The keywords may appear in either Column B or Column D in Sheet1. For each row it finds, I need it to copy the entire row to Sheet2 starting on row 2 since row 1 has headers.

    What I'm able to get so far is just searching under one column only instead of searching across two columns.

    I hope my explanation isn't too confusing and I thank you in advance. I've attached a sample of the file with mock data and posted the VBA I've been using so far to search under one column.

    Any help?

    DataSample.xlsx

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Try this it works on the sample but will need minor amendments for the full package but it's simple enough.

    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: How to search across 2 columns for keywords from a list and copy each row to a new she

    As an option

    Please Login or Register  to view this content.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Hi, Ab33,

    from the VBA-Help:
    Const vbTrue = -1 (&HFFFFFFFF)
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Holger,
    I am not sure what are you referring to? Could you please explain?

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    AB

    I think what Hogler is referring to is this line. Where 1 should be -1

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Mike,
    Thanks!
    I thought, generally speaking in computer programming, 1 equals to True and 0 is false

  8. #8
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Most electronic systems work on negative logic where the inverse is true :-)....... There is a good reason for it but I can't for the life of me remember why...

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Andy!
    Thanks,
    So you reckon 1 is false and o is true

  10. #10
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Not in Excel no....

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    So, my first assumption was right then

  12. #12
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Yeah, sorry... Didn't mean to confuse the situation

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Andy,
    I am still not sure why do I need to use -1, as suggested by Mike and Holger,

  14. #14
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    No idea mate...

  15. #15
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Hi, AB33,

    generally speaking in computer programming, 1 equals to True and 0 is false
    0 is False both in Excel and VBA, in Excel 1 means True while in VBA itīs -1. You maybe go back to the first programmers to ask why they choose to do so.

    Ciao,
    Holger

  16. #16
    Registered User
    Join Date
    04-14-2012
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    I've tried all the macros and they worked really well. I am so appreciate of everyone's help, thank you so much!

    AB33, is there a way to add in a line somewhere that will work like a "ClearContents" where the search result will be cleared away each time the Macro is used as the Data Set on Sheet1 will always be updated with more rows of data and some Keywords in Sheet3 may be removed.

    Thank you again everyone.

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Keith,
    Amended code. Clears the data in sheet2-output sheet before you run the code.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    04-14-2012
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    This is awesome, thanks AB33!

    You have no idea how much this will help. Thanks everyone!

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

    Re: How to search across 2 columns for keywords from a list and copy each row to a new she

    Keith,
    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)

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