loop through sheets in the workbook and copy specific range from each sheet to a summary sheet.

InnaG

New Member
Joined
Mar 18, 2019
Messages
22
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Good morning,
I have a spreadsheet with 5 or more sheets and I am trying to create code that will loop through sheets and copy the same range from each sheet to the "Overall Summary" sheet. The range should be copied into the next blank row.

Here is the code I have so far, please help.

Thank you

Code:
Sub CopyRangeFromMultiSheets()
'
' CopyRangeFromMultiSheets Macro
'


Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim CopyRng As Range


    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With




    'loop through all worksheets and copy the data to the DestSh


    Set DestSh = Worksheet("Overall Summary")

    For Each sh In ActiveWorkbook.Worksheets
        If sh.Name <> DestSh.Name And sh.Name <> "Data Quality" And sh.Name <> "Confidence Level" And sh.Name <> "Standard Reporting Rules" And sh.Name <> "s*" Then


            'Find the last row with data on the DestSh
            Last = LastRow + 1


            'Fill in the range that you want to copy
            Set CopyRng = sh.Range("A5:G14")


          Sheets("Overall Summary").Select



End If


Next ws


End Sub
 
Last edited by a moderator:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about
Code:
Sub InnaG()
   Dim Ws As Worksheet, DestSh As Worksheet
  
   Set DestSh = Worksheets("Overall Summary")
   For Each Ws In Worksheets
      If Ws.Name <> DestSh.Name And Ws.Name <> "Data Quality" And Ws.Name <> "Confidence Level" And Ws.Name <> "Standard Reporting Rules" And Ws.Name <> "s*" Then
         Ws.Range("A5:G14").Copy DestSh.Range("A" & Rows.Count).End(xlUp).Offset(1)
      End If
   Next Ws
End Sub
 
Upvote 0
Code:
Sub CopyRangeFromMultiSheets()    
Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim CopyRng As Range


    With Application
        .ScreenUpdating = False
        .EnableEvents = False


        Set DestSh = Sheets("Overall Summary")
        For Each sh In ActiveWorkbook.Worksheets
            Select Case sh.Name
            Case DestSh.Name, "Data Quality", "Confidence Level", "Standard Reporting Rules"
            Case Else
                'If sh.Name <> "s*" Then
                If Not sh.Name Like "s*" Then
                    Last = DestSh.Cells(Rows.Count, 1).End(3).Row + 1
                    sh.Range("A5:G14").Copy
                    Sheets("Overall Summary").Cells(Last, "A").PasteSpecial xlValues
                End If
            End Select
        Next sh


        .ScreenUpdating = True
        .EnableEvents = True
    End With


End Sub
 
Last edited:
Upvote 0
Solution
Thank you, but I keep getting an error msg for Set DestSh = Worksheet("Overall Summary")
 
Upvote 0
Thank you, but I keep getting an error msg for Set DestSh = Worksheet("Overall Summary")

Typo on my part it should be
Code:
Set DestSh = Worksheet[COLOR=#ff0000]s[/COLOR]("Overall Summary")
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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