VBA to Create Summary Sheet

Topher177

New Member
Joined
Nov 24, 2015
Messages
4
Hello. I'm looking to create a VBA code that will loop through every worksheet within my workbook (except for the summary sheet) and search for a text string. Once this string is found, I would like the code to grab the 5 cell rows to the right of the looked up cell and paste special this information on a summary sheet. Please help.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the Board!

I'd start by recording a macro on a few sheets. You can post the resulting code back here for everyone to take a loot.
 
Upvote 0
Change part in blue and try:
Rich (BB code):
Sub UpdateSummary()

    Dim ws      As Worksheet
    Dim wsSum   As Worksheet
    
    Dim rng     As Range
    
    Dim x       As Long
    Dim LR      As Long
    
    Const FindString As String = "xxxxx"
    
    Set wsSum = Sheets("Summary")
    LR = wsSum.Cells(rows.count, 1).End(xlUp).row + 1
    
    Application.ScreenUpdating = False
    
    For Each ws In ThisWorkbook.Worksheets
        With ws
            If .Name <> wsSum.Name Then
                Set rng = .Cells.Find(what:=FindString, LookIn:=xlValues)
                
                If Not rng Is Nothing Then
                    wsSum.Cells(LR, 1).value = rng.Offset(0, 5).value
                    LR = LR + 1
                    Set rng = Nothing
                End If
                
            End If
        End With
    Next ws
    
    wsSum.Select
    
    Application.ScreenUpdating = False
    
    Set wsSum = Nothing

End Sub
 
Upvote 0
JackDanIce - Thank you for your help! The code you posted works great except that it is currently only returning the 5th cell from each table. I'm sorry if I wasn't clear but I will need to copy the whole range (5 cells) to the right of the unique identifier.
 
Upvote 0
Experiment with parts in blue and try:
Rich (BB code):
Sub UpdateSummary()

    Dim ws      As Worksheet
    Dim wsSum   As Worksheet
    
    Dim rng     As Range
    
    Dim x       As Long
    Dim LR      As Long
    
    Const FindString As String = "xxxxx"
    
    Set wsSum = Sheets("Summary")
    LR = wsSum.Cells(Rows.Count, 1).End(xlUp).Row + 1
    
    Application.ScreenUpdating = False
    
    For Each ws In ThisWorkbook.Worksheets
        With ws
            If .Name <> wsSum.Name Then
                Set rng = .Cells.Find(what:=FindString, LookIn:=xlValues)
                
                If Not rng Is Nothing Then
                    wsSum.Cells(LR, 1).Value = rng.Resize(1, 5).Value
                    LR = LR + 1
                    Set rng = Nothing
                End If
                
            End If
        End With
    Next ws
    
    wsSum.Select
    
    Application.ScreenUpdating = False
    
    Set wsSum = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,292
Members
449,308
Latest member
VerifiedBleachersAttendee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top