+ Reply to Thread
Results 1 to 14 of 14

Macro to Search and Copy Multiple Keywords into Another Sheet

  1. #1
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Question Macro to Search and Copy Multiple Keywords into Another Sheet

    I’d like to alter the current macro I have pasted below but I’m having trouble identifying where I should add/change lines in the code. Maybe you can help? Here are the details:

    Ideally, I’d like this macro I pasted below to search for keywords listed in column AK (there are multiple keywords found in each cell of this column, each separated by commas within the cell) of worksheet titled 'Octopus".

    Once the macro has identified which rows contain keywords in column AK (the macro currently has an input box for the user to type the keyword into) I’d like the macro to copy these rows (information from columns A-AK would need to be copied) and paste them into sheet named Sheet1.

    • The macro below doesn’t search for multiple keywords at a time which isn’t ideal.
    • It doesn’t copy over the comment box information from these rows (comments are located in columns D and E of each row) into Sheet1.
    • It doesn't allow users to input more than one keyword into the input box at a time, but should copy rows matching both keywords that were searched.
    • It does correctly copy the header row from sheet Octopus (row 4) and paste it into Sheet1 and I'd like that to stay.
    • Copy entire rows with their information including their comment boxes over into Sheet1
    • Allow searching for multiple keywords matches to be searched at once,
      copy
      over rows that match both keywords at a time into Sheet1

    Please Login or Register  to view this content.
    Last edited by Bangarang; 08-05-2010 at 10:54 AM. Reason: Solved issue by Foxguy

  2. #2
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Hello there, just wanted to bump this up to see if I could get any help with this question. If you have any ideas at all feel freel to post a reply. Thank you!

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Hi Bangarang;

    Here's a file with a userform in it to do what you want. I didn't have a workbook to test it on, so back up first.

    If you don't know how to put the userform into your workbook:
    In the VBE, just drag it from my project and drop it on your project.

    Important
    In your post you said to copy into Sheet1, but your macro was copying from Sheet1 into Sheet14. Also copied from Sheets("All Levels - Combined") onto Sheet1. There was not a Sheets("Octopus") anywhere in your macro. So I really don't know where you wanted to copy from or to. So be sure and change the sheet names as instructed here.
    To modify it to your workbook:
    1) Double Click on "Userform1" to open the form.
    2) Double Click on the form to open the code window.
    3) Find Sub "SearchKeywords"
    4) Change the worksheet names in the section between the '****************

    If you don't know how to run the userform:
    In a sub just "UserForm1.show"
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  4. #4
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Thanks Foxguy!

    I'll take a look at this on Monday morning when I get back to my work computer. I really appreciate your efforts.

    (as far as the sheet names went, I was just changing them to something that I could recognize so I could later edit them as needed)

  5. #5
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Hey Foxguy,

    I cannot for the love of god get this form to work. I've been trying to copy and past the code into a blank macro that I just recorded a couple clicks with but it will not copy or work the way it should.

    Would it be possible to reply back with the step by step process to working with this userform? I greatly appreciate your help! Thank you sir!
    Last edited by shg; 07-30-2010 at 03:02 PM. Reason: deleted spurious quote

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    There is no code in my file to copy & paste. I converted your InputBox to a Userform so that the user could easily type in more than 1 word. Otherwise the user would have to be given instructions on how to enter more than 1 word in the InputBox.

    To move the Userform into your workbook:
    1) Open the Project Explorer (Alt+F11 opens VBE, then Ctrl+R to open Project Explorer).
    2) Find you workbook and my workbook (mine will be named "VBAProject(Macro to Search and Copy Multiple Keywords into Another Sheet)" and yours will be named "VBAProject(YourWorkbookName)")
    3) Find the UserForm in my workbook, and drag & drop it into yours (left mouse click the userform & hold button down, move the cursor to your workbook and release mouse button)
    4) Double click on the userform in Project Explorer (this will open the form for editing).
    5) Double click on the form itself (not one of the boxes). This will open the code behind the form.
    6) Find the sub named "SearchKeywords" and modify the sheet names in the section between the '****************

  7. #7
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Question Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Quote Originally Posted by foxguy View Post
    There is no code in my file to copy & paste. I converted your InputBox to a Userform so that the user could easily type in more than 1 word. Otherwise the user would have to be given instructions on how to enter more than 1 word in the InputBox.

    To move the Userform into your workbook:
    1) Open the Project Explorer (Alt+F11 opens VBE, then Ctrl+R to open Project Explorer).
    2) Find you workbook and my workbook (mine will be named "VBAProject(Macro to Search and Copy Multiple Keywords into Another Sheet)" and yours will be named "VBAProject(YourWorkbookName)")
    3) Find the UserForm in my workbook, and drag & drop it into yours (left mouse click the userform & hold button down, move the cursor to your workbook and release mouse button)
    4) Double click on the userform in Project Explorer (this will open the form for editing).
    5) Double click on the form itself (not one of the boxes). This will open the code behind the form.
    6) Find the sub named "SearchKeywords" and modify the sheet names in the section between the '****************


    I apologize for all the trouble I'm giving you but I'm getting an error after I perform the steps you mentioned in your last post.

    I get this error: "Run-time error '1004': Method "Range" of object'_Global" failied. When I click on debug it highlights this line:

    Please Login or Register  to view this content.
    I think I am getting the error after the first time I try to run it, or after I click the command button twice. It also doesn't seem to be pasting the search results after I click once, the inbox just stays open and the workbook is unchanged. It's really weird. Below is how my code reads.

    For reference, keywords are being searched from the first sheet in the workbook, this sheet is presently named "All Levels - Combined"....

    Then the goal is to be able to have two key words searched and once, with the results pasted into sheet named "Sheet1"

    Do you think these sheet names are the reason for the error? VBA code is confusing to read so maybe I changed the sheet names in the section you refered to incorrectly?

    Here's the code copied and pasted from the viewing the code form "Userform1"


    Please Login or Register  to view this content.
    What are your thoughts? Am I an idiot and doing this wrong? I've spent a bunch of time looking up the error codes and trying out different suggestions from the internet as I didn't want to bug you again but I thought after 4 hours of trying I'd ask you again. I'm sorry this isn't getting resolved quickly, I really do appreciate the help you've been giving me. And yes, I'm getting pretty desparate

  8. #8
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    The error
    Method "Range" of object'_Global" failied on the line
    Please Login or Register  to view this content.
    seems to be saying that the macro couldn't find the range. I would initially assume that the code was working on an empty sheet.

    This file will verify that there is something on the sheet it's copying from.
    I assume from your message that you were getting the form opened where it was asking for 2 Search Strings.

  9. #9
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Quote Originally Posted by foxguy View Post
    The error
    seems to be saying that the macro couldn't find the range. I would initially assume that the code was working on an empty sheet.

    This file will verify that there is something on the sheet it's copying from.
    I assume from your message that you were getting the form opened where it was asking for 2 Search Strings.

    Wow!!! Thanks Foxguy for pulling through once again. I'm very pleased this worked!

    I do have one change that I was wondering if you could help with and then this will be finished...

    The question is: When searching two keywords at once, the results that are copied include any row that contains either of the two keywords entered. Can this be changed to include only those rows that contain both keywords?

    If this is possible let me know. I'm not sure how or where in the code to define this, so I apologize for asking another question of you.

    Other than that, the thing runs magnificently! I'm crazy happy to have had all your assistance in this and I cannot thank you enough! Thank you very much sir!

  10. #10
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet


  11. #11
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Quote Originally Posted by foxguy View Post
    Okey Dokey
    Hi again Foxguy!

    I get this error when I try using the new form:
    "Run-time error 9: Subscript out of range"

    And then the debugger highlights this line in the userform1 code:

    Please Login or Register  to view this content.

    Any ideas? Is there anything I can do to make this stop? We're so close to getting this to work! Thanks again for your incredible help!

    crossing my fingers

  12. #12
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Sorry, put it on the wrong line

  13. #13
    Registered User
    Join Date
    05-14-2010
    Location
    The Midwest, USA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    Foxguy it works!!!!!!!!!

    You're amazing. Thanks a million for your excellent help with this!

  14. #14
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Macro to Search and Copy Multiple Keywords into Another Sheet

    You're Welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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