+ Reply to Thread
Results 1 to 18 of 18

Search multiple sheets and copy results to new sheet

  1. #1
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Search multiple sheets and copy results to new sheet

    Hello,

    I have a workbook with 50+ sheets. Within each sheet are rows of data in column A that I'd like to search for specific text.

    I'd like to search each row from every sheet for specific words (e.g. "7 days" AND "Monday" AND "Tuesday" etc.) then copy the entire row containing all my search text in a new sheet on column A along with the name of the sheet it was found in in column B and the row number it came from in column C.

    What I am trying to accomplish is to search through all the sheets and post results in new sheets for each search string.

    Thank you kindly for your expertise and help.
    Last edited by augr; 06-18-2014 at 06:45 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Give this a try:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Thanks so much stnkynts. I ran it but it doesn't seem to be posting results. I get a blank array name sheet. I'm using Excel 2007 if that makes a difference. Thanks again.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Shouldn't matter. It works just fine for me when I tested it. Submit your workbook.

  5. #5
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Hi stnkynts,

    Thanks for your help... very much appreciated. Your solution looks very elegant. I will send you a PM with the workbook if that's ok. Also I noticed that the search string produces results for each text in the array on new sheets individually. I was hoping the result would be for all the terms in the array. e.g. the result sheet would show all rows that contain all the text in the array ("7 days", "Monday", "Tuesday"), then I could modify the array for say ("Wednesday", "Thursday") and run the macro again to show all the rows containing all the text in the new array.

    Thanks again!

  6. #6
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Thumbs up Re: Search multiple sheets and copy results to new sheet

    Hi again stnkynts, it doesn't look like I can attach a file to a PM. I've attached it to this post. Thanks for your help!
    Last edited by augr; 06-18-2014 at 06:47 PM. Reason: sorry i had to remove the attachment

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Here is what you said in your original post indicating you wanted multiple sheets. Is this not the case now?

    and post results in new sheets for each search string.

  8. #8
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Yes that's correct but I meant ALL the words in the string not the individual words. Maybe I didn't clarify correctly when I said AND?

    e.g.
    • ROW 1 DATA: This is 7 days a week but might be closed Monday, Tuesday, Wednesday.
    • SEARCH STRING: ("Monday", "Wednesday")
    • RETURN: This is 7 days a week but might be closed Monday, Tuesday, Wednesday.
    • SEARCH STRING: ("Monday", "Saturday")
    • RETURN: No result (since the row does not contain both words "Monday" AND "Saturday")

    Thanks!

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Ok. Try this:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Thumbs up Re: Search multiple sheets and copy results to new sheet

    Very very nice stnkynts! Works well but it seems to be pulling non related results.

    e.g.

    When I search ("Mon")
    I also get results that don't contain the word "Mon" such as:
    -Knights of Columbus #2170, 20 Church St, Game play: Tue-7:00, Phone: (603) 934-9863.
    -Plaistow Fish & Game Club Inc, 18 MayrayAve, 03865, Game play: Tue-6:45 pm, Phone: (603) 382-3675.
    -Bingo, 184 Milton Rd, 03867-3106, Game play: Tue-Thu-Fri-Sun-6:30, Phone: (603) 335-2021.

    Also when I search, for example, ("7 days", "Mon", "Tue") it returns results that contain ANY of the array words and not ALL of the array words. I was hoping the result would return rows containing ALL of the words in the array so it filters out rows that do not contain ALL the words in the array.

    We're very close thank you so much! Very much appreciated.
    Last edited by augr; 06-17-2014 at 12:18 PM.

  11. #11
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Due to the nature of the text in column A the macro is going to search for "mon" throughout the entire string. So for example if you have the word "Diamond" in the the string such as this:

    -Diamond Rose, 10639 Kenai Spur Highway, 99611, Game play: Tue-Thu 7:00 pm and Sun 6:00 pm, Phone: (907) 283-6445.
    It will return it even though it isn't on Monday. In addition, I believe the string above will also need to be counted when "Wed" is entered but it will not.

    It is possible to correct for these issues but by no means easy due to the layout of the string. My time at the moment is very limited and I don't know when I will be able to address all the intricacies that you require.

  12. #12
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Yes that's correct and it's perfectly ok if it finds the search string within words as your example "mon" within "diamond".

    I'm not looking for perfection but simply results that contain ALL the search words in the array string. As in your example, search ("mon", "wed") would return lines that contain BOTH "mon" and "wed" even if the line refers to "diamond" and "wedding" OR "monday" and "wednesday" etc. Thanks!

  13. #13
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    Ok. I rewrote the code to incorporate a positive match on all strings within the Array. I also did soem reworking to speed it up a bit. Let me know:

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Thanks stnkynts seems to be working with all the terms in the array now.

    I get an error: "Object variable or With block variable not set" then I have to reopen the workbook so I can run the macro again (otherwise run button is greyed out). Also, it doesn't seem to be pulling all the results. e.g. "7 days" (I'm assuming it's not case sensitive) has 514 records but the macro stops at 197.

    Thanks for the effort mate I really appreciate it.

  15. #15
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    What line is highlighted when you get the "Object variable or With block variable not set" error? I can't seem to replicate the error.

    I'm assuming it's not case sensitive
    It very much is case sensitive

    Replace this line to make it not case sensitive:
    Please Login or Register  to view this content.
    Last edited by stnkynts; 06-18-2014 at 05:40 PM.

  16. #16
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Thanks for the case sensitive revision.

    I'm manually create a new blank sheet, have my A1 cell highlighted, run the macro then as it's working, it automatically kicks over to VB and pops up the error. Attached is a screenshot.

    Thanks so much!


    error.jpg

  17. #17
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Search multiple sheets and copy results to new sheet

    If you click ok it will highlight a line of the code, what line gets highlighted. You don't need to manually create a new blank sheet. It will create 1 for you.

  18. #18
    Registered User
    Join Date
    06-09-2014
    Location
    Hawaii
    MS-Off Ver
    Office 365
    Posts
    75

    Re: Search multiple sheets and copy results to new sheet

    Interesting.
    1. When I have a new blank sheet and run the macro, it throws the exception. I press ok and it goes back to the spreadsheet without highlighting anything in the VB code.
    2. When I don't have a new sheet but already have results posted, no error and seems to run fine even if I revise the array and run the macro again, it overwrites fine.
    3. When I don't have a new sheet or results already, and run the macro from any page, no error and posts results just fine.

    I think we're good I can live with this.

    Thanks so much stnkynts! You're a VBA god!

+ 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 Multiple Sheets and copy results
    By discodave22 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2014, 04:40 AM
  2. [SOLVED] I need to search for a word on multiple sheets and copy the entire row to a new sheet
    By jkm750 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2013, 12:13 AM
  3. Search for Multiple String Values on Multiple Sheets and Copy Rows to New Sheet
    By rrtikker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 12:21 PM
  4. [SOLVED] Search multiple sheets, then paste results in new sheet
    By Paul M in forum Excel General
    Replies: 1
    Last Post: 01-08-2006, 03:30 PM
  5. [SOLVED] Search multiple sheets, then paste results in new sheet
    By Paul M in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-08-2006, 03:30 PM

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