+ Reply to Thread
Results 1 to 10 of 10

Search all worksheets and paste all rows w/search criteria to single sheet

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Search all worksheets and paste all rows w/search criteria to single sheet

    Good day, Gurus.

    I've got a workbook that I use for budgeting. Each month is kept on a new worksheet, and it already has about 50 worksheets. I would like to enter a word into an input box, have Excel search each worksheet for all instances of that word, and copy every row containing that word to the worksheet named "Search"

    I haven't a clue of the best way to do this, and I can't write code, but can read it decently. Here's what I envision:

    Please Login or Register  to view this content.
    If there is a better, simpler or more reliable way to accomplish my goal, I"m definitely open to suggestions. Thanks in advance for any help you can offer.

    Hutch
    Last edited by [email protected]; 01-22-2012 at 01:31 PM.

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Lightbulb Re: Search all worksheets and paste all rows w/search criteria to single sheet

    Hi,

    I created sample file executing scenario You asked for.

    I hope you and other users will find it useful

    whole code here:
    Please Login or Register  to view this content.
    Last edited by MaczaQ; 01-19-2012 at 05:49 PM. Reason: +1 'added row index
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to rate it. To thank someone who has helped you, click on the star icon below their name.
    - This way you will add him some reputation points ... thanks in advance.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    Maczaq - The book was locked for editing and had external links. The code was on your results worksheet rather than a standard module, and I couldn't even step through it because F8 wouldn't work. If I just pushed the button I got an error, probably due to the external links. Frankly, the whole thing looked kind of fishy.

    Thanks anyway.

  4. #4
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    hi,

    I export code to module, and save as XLS in excel 2003, maybe this time it will work for you; please check.

    Just go to VBA editor (ALT+F11) and start procedure "searchAndCopy()" in Module1 for test it.
    Attached Files Attached Files
    Last edited by MaczaQ; 01-20-2012 at 04:04 AM. Reason: new file uploaded

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    Good morning, maczaq. The macro appears to run perfectly in your sample workbook, but when I import the code, (function included), into my test workbook in Excel 2007 I get runtime errors. The initial ones were "missing object or library", so I set "what" and "r" as variables, but now it stops on "toCopy". I din't know if that is a command 2007 doesn't recognize or what.

  6. #6
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    it is string variable = try to init it
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    Hey, maczaq. The following code seems to work in 2007, with a few glitches. In my test workbook, it doesn always return rows that have the search criteria. I think it is because of the way we are searching. I want the macro to copy the row to the Search worksheet if it finds the word anywhere in the cell. I thin this only returns the results if the search is an exact match to the cell contents.

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    I have attached a cleaned up and simplified version of my Bill Tracking Log, containing the "SearchAndCopy" macro and the "LookingFor" function. You will notice that if you run the macro, and type "CWD" or "Wal Mart" as the search criteria, then it will paste all rows that have a cell matching "CWD" or "Wal Mart" to the Search worksheet. That is good.

    However, If I type only part of a cell value as the search criteria, such as "tobacco" or "Bobbie", then it returns no results. Also, it returns no results if I type in a numer or dollar amount, such as $80.00. Ideally, either of these search criteria should paste every row to the "Search" worksheet if it finds those values anywhere in any of the cells on any of the worksheets.

    Is this possible?
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    Hi Hutch,

    I think it is because function LookingFor returns only rows where was find a cell with equal value to seek string

    look in line:
    Please Login or Register  to view this content.
    try to change it into:
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Search all worksheets and paste all rows w/search criteria to single sheet

    maczaq - Works beautifully. Thanks!

+ 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