VBA Copy multiple sheets

AccountantinExcel

New Member
Joined
Sep 10, 2018
Messages
10
Good morning,

I am looking to use VBA to copy multiple sheets then paste values to a Summary sheet then remove all rows if Column A = 0. I have started with this code to copy sheets but am getting errors.

Sheet names:
G1 Sort Table
G2 Sort Table
G3 Sort Table
G4 Sort Table
G5 Sort Table
G6 Sort Table
G7 Sort Table
G8 Sort Table
G9 Sort Table
G10 Sort Table


Has anyone done this before?


"Sub SummurizeSheets()
Dim ws As Worksheet
Dim j As Integer, col As Integer


Application.ScreenUpdating = False


Sheets("Summary").Activate




For Each ws In Worksheets
If ws.Name = "G1 Sort Table" Then
ws.Range("A1:M40000").Copy


Row = Worksheets("Summary").Range("M40000").End(xlToLeft).Column + 1
Worksheets("Summary").Cells(1, Row).PasteSpecial xlPasteValues
Application.CutCopyMode = False


End If


Next ws
Columns(1).Delete
Range("A1").Activate
Application.ScreenUpdating = True
End Sub"





Thanks,

Anthony
 
It worked but it does not paste values as my first formula did and also they are pasting to the right of the last one and not below. For example

It is doing this

A B C D E F
G1 G1 G1 G2 G2 G2



Should do this

A B C
G1 G1 G1

G2 G2 G2
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Your original code appeared to be finding the last column in row M and using that to paste.

If you want to paste down the sheet try this.
Code:
Sub SummurizeSheets()
Dim ws As Worksheet
Dim I As Long
Dim arrSheets As Variant

    arrSheets = Array("G1 Sort Table", "G2 Sort Table", "G3 Sort Table") ' add the rest of the sheet names as needed

    Application.ScreenUpdating = False

    For I = LBound(arrSheets) To UBound(arrSheets)
        Set ws = Sheets(arrSheets(I))
        ws.Range("A1:M40000").Copy 
        Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
    Next I

    Application.CutCopyMode = False

End Sub
 
Last edited:
Upvote 0
Your original code appeared to be finding the last column in row M and using that to paste.

If you want to paste down the sheet try this.
Code:
Sub SummurizeSheets()
Dim ws As Worksheet
Dim I As Long
Dim arrSheets As Variant

    arrSheets = Array("G1 Sort Table", "G2 Sort Table", "G3 Sort Table") ' add the rest of the sheet names as needed

    Application.ScreenUpdating = False

    For I = LBound(arrSheets) To UBound(arrSheets)
        Set ws = Sheets(arrSheets(I))
        ws.Range("A1:M40000").Copy 
        Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
    Next I

    Application.CutCopyMode = False

End Sub


That worked!

Thank you for the assistance.

Anthony
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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