+ Reply to Thread
Results 1 to 13 of 13

Using VBA to search for keywords in data set and return results in another sheet

  1. #1
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Using VBA to search for keywords in data set and return results in another sheet

    Hi everyone,

    Hope you all are doing well. I have this irritating issue with a vba code I am trying to perfect.

    Sheet2 - contains data set

    Sheet1 - search query using keywords entered in cell "H4""

    Essentially I want to search for key words that are entered in sheet1 cell "H4". I am trying the search to take place data set located in Sheet2 column G7:G20000 and H7:H20000. If keywords match any one of cells in Column G or H, then paste that row in sheet1, but only specific columns from the matching row, e.g. Column F, G, H, K and M from sheet2 into Sheet1.

    I am trying to get the pasting down starting in cell "B11" in sheet1

    I also can't seem to have search results cleared every time I run this script.

    I have the following code:

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

    Can someone please help me clean up this vba?
    Last edited by Rez4ul; 09-02-2016 at 08:36 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    This is only guess due to unclear sheet layouts.
    Please Login or Register  to view this content.
    However, if you have heading in "Classification Requests" sheet, Advanced filter would be the best to apply.

  3. #3
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Hi,

    Thanks so much for trying.

    Sheet1 = "Keyword search for a product" = worksheet in which I will enter a "keyword" and return a result in
    Sheet2 = "Classification Requests" = data set in which the "keyword" I enter in sheet1 will look in.

    I have tried the code you indicated above, but I could not get it to work. Few questions:

    (1) will it give me more than 1 results? I am trying to get more than one search result.
    (2) how would I be able to search in two columns. I see that the code above only searches in column "H:H" of sheet2

    thanks again

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    OOps, it should be
    Please Login or Register  to view this content.
    Anyway, uploading sample workbook helps.

  5. #5
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Hi,

    I got it to work. Thanks a muillion. I am unable to upload the file for some reason.

    Few more clarificaitons:

    (1) hoow can I get pasted rows to show alterenating row colour?

    (2) If I want the search to start at row 7 in sheet 2, then do I just change G:H --> "G7:H7"?

    Thanks again,

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    1) You can apply conditional format. e.g
    Select A11:F?
    Formula : =AND($A11<>"",MOD(ROW(),2))

    2) Try change to
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Hey,

    I have everything set up. Search and found is working, but there are two issues:

    (1) format gets carried over -- which is something I do not want. I am trying to keep text only.
    (2) the search is still not starting from row 7. it seems to still cover anything above row 7, e.g. row 6.

    HTML Code: 

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    That's why I was keep saying "Upload a workbook".
    No one can see your file and read your brain...

    1) try change to
    Please Login or Register  to view this content.
    2) How could it be possible to find something in row 6 when search range is G7:H1048576 ?

  9. #9
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Hi,

    I was trying to attach a file and it was not letting me.

    I think it finally worked.

    I noticed that the search results repeat each match three times.

    thanks,
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Try
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-29-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    13

    Re: Using VBA to search for keywords in data set and return results in another sheet

    THi,

    thanks again for trying. That code filters my original data set in sheet2 and then crashes.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Can you do a step debug and find out the reason for crash?

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Using VBA to search for keywords in data set and return results in another sheet

    Or try this
    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)

Similar Threads

  1. [SOLVED] Search/find all worksheets return results on new sheet
    By Morleyb in forum Excel General
    Replies: 1
    Last Post: 06-28-2016, 03:51 PM
  2. VBA to search duplicate & return all possible results to Main Sheet?
    By beepbeep_go in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2015, 11:27 AM
  3. [SOLVED] VBA looking for multiple keywords and return concatenated keywords, that were found
    By Kpacu007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2014, 06:03 AM
  4. Search for Keywords and Return the Appropriate Item
    By uberathlete in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-05-2014, 12:52 AM
  5. [SOLVED] Search for keywords and copy rows containing keywords to new sheet
    By lenorsk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-15-2013, 06:54 AM
  6. [SOLVED] HDI - Return multiple keywords in a text column based on a set of available keywords
    By zneiley in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2013, 01:32 PM
  7. Replies: 3
    Last Post: 07-17-2013, 03:41 AM

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