+ Reply to Thread
Results 1 to 4 of 4

Altering VBA find function to search entire workbook

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Altering VBA find function to search entire workbook

    Hi everyone,

    The code below is for a button which will search a worksheet (.find function) to find a value that has been typed into the textboxes on the form. It subsequently copies the entire row of any hits and pastes them into a new sheet.

    I would like to alter the code so that it searches ALL the sheets within the workbook.

    I would really appreciate any help!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Altering VBA find function to search entire workbook

    try this.
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Altering VBA find function to search entire workbook

    Hi David,

    Thanks for the quick reply. I get a compile error: Next without For

  4. #4
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Altering VBA find function to search entire workbook

    Since I know what it's like to wait, to give you an answer, and not meaning to step on Tinbendr ...

    What he's doing is wrapping your code inside a loop that executes the loop's contents for each worksheet. The key lines are

    Dim ws As Worksheet

    and

    For Each ws In Worksheets
    With ws
    ws.Unprotect

    and finally

    next ws

    I haven't checked, but either he just left off the last one, or the "next" at that point connects to some other "for." Also note that the "With" can be further capitalized on; what he shows leaves the prefix on.

    He has two more lines
    ws.Protect userinterfaceonly:=True
    ws.EnableSelection = xlNoRestrictions
    which you would have to decide to use or not. As that goes, the .unprotect might be debated as well.

    HTH. Is this a class assignment?
    Last edited by Oppressed1; 09-20-2012 at 03:31 PM.

+ 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