+ Reply to Thread
Results 1 to 5 of 5

VBA Code to search across all worksheets in a workbook

Hybrid View

  1. #1
    jjward101
    Guest

    VBA Code to search across all worksheets in a workbook

    Hi,

    I have a very simple workbook that will log projects by month. There is one worksheet for each month of the year. I need to be able to search across all worksheets to return results from the same row. I have tried to install code that I have found within this forum, but it seems that my ability to modify that code to meet my need is not great.
    WOuld anyone mind taking a look and telling me what exact code i need?
    File attached
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA Code to search across all worksheets in a workbook

    What kind of results? The sheet is blank.

  3. #3
    jjward101
    Guest

    Re: VBA Code to search across all worksheets in a workbook

    Sorry... I uploaded the proper file.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA Code to search across all worksheets in a workbook

    If you did attach another workbook it still looks like the same one as before.

    It could be possible you need to save it as a different name and then attach it.

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA Code to search across all worksheets in a workbook

    Try this code. I added a new Summary sheet that populates when the code is run via the summarize button.

    Option Explicit
    
    Sub ConsolidateData()
    Dim Sr, lr, lrs As Long
    Dim w As Worksheet
    Dim Rng As Range
    Dim x As Date
    
    Optimiser (True)
    On Error Resume Next
    On Error GoTo 0
    Sr = 3
    'x = Sheets("Summary").Range("B1").Value
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    Sheets("Summary").Range("A2:O" & lr).Delete
    
    For Each w In ActiveWorkbook.Sheets
    On Error Resume Next
    If w.Name = "Summary" Or InStr(w.Name, "_") >= 1 Then GoTo Skip
        w.Select
        lrs = Cells(Rows.Count, 1).End(xlUp).Row
        Set Rng = w.Range("A5:O" & lrs)  '.Select 'Cells.Select
        With Rng
            .AutoFilter
            .AutoFilter Field:=2, Criteria1:="<> """
            .SpecialCells(xlCellTypeVisible).Copy
            w.AutoFilterMode = False
        End With
        Sheets("Summary").Activate
        Sheets("Summary").Range("A" & Sr).Value = w.Name
        Sheets("Summary").Range("A" & Sr + 1).PasteSpecial xlValues
        Sheets("Summary").Range("A" & Sr + 1).PasteSpecial xlFormats
        ' Turn off filter
        
    Sr = Sr + lrs - 2
    Set Rng = Nothing
    Skip:
     Next
        
    Optimiser (False)
        
    End Sub
    
    Private Sub Optimiser(T As Boolean)
    T = Not T
    Application.ScreenUpdating = T
    Application.DisplayAlerts = T
    Application.EnableEvents = T
    Application.DisplayStatusBar = T
    ActiveSheet.DisplayPageBreaks = False
    
    If T = False Then
    Application.Calculation = xlCalculationManual
    Else
    Application.Calculation = xlCalculationAutomatic
    End If
    
    End Sub
    Attached Files Attached Files

+ 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. search on multiple worksheets all in the same workbook
    By bighkyfan in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 07-18-2016, 06:41 AM
  2. [SOLVED] VBA code to create a workbook and copy or move worksheets in to workbook through loop
    By anishkumarvs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 05:40 AM
  3. Please help with VBA to search through same column on different worksheets in a workbook
    By damilaredavids in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2012, 10:27 PM
  4. Search all worksheets of a workbook
    By Jennster in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2012, 07:59 AM
  5. Looking to search multiple worksheets within a workbook
    By chassenj in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-31-2012, 02:45 PM
  6. [SOLVED] Search all worksheets in a workbook...
    By Peter in forum Excel General
    Replies: 6
    Last Post: 01-26-2005, 08:06 AM

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