Copying multiple worksheets into one onto a separate workbook

tgraham

New Member
Joined
Jul 29, 2016
Messages
1
I have a workbook (WB1) that contains multiple worksheets. I need my current workbook (WB2) to go into workbook (WB1) and copy the multiple worksheets and combine them into one worksheet in WB2.

I was able to work out... within the same workbook to combine all the worksheets into one but have had trouble copying and combining the data into an separate workbook.

Sub CombineData()


Dim Sht As Worksheet
For Each Sht In ActiveWorkbook.Worksheets
If Sht.Name <> "Master" And Sht.Range("A1").Value <> "" Then
Sht.Select
LastRow = Range("A65536").End(xlUp).Row
Range("A1", Cells(LastRow, "T")).Copy
Sheets("Master").Select
Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Else
End If
Next Sht




End Sub

Please help. :confused:
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Perhaps.
Code:
Sub CombineData()
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim Sht As Worksheet
Dim LastRow As Long

    Set WB1 = ActiveWorkbook
    Set WB2 = Workbooks("NameOfTheWorkbookToCopyTo.xlsm")

    For Each Sht In WB1.Worksheets
        If Sht.Name <> "Master" And Sht.Range("A1").Value <> "" Then
            With Sht
                LastRow = .Range("A65536").End(xlUp).Row
                .Range("A1", .Cells(LastRow, "T")).Copy WB2.Sheets("Master").Range("A65536").End(xlUp).Offset(1, 0)
            End With
        End If
    Next Sht

End Sub
 
Upvote 0
I have a similar question to this thread. I need to copy multiple columns (E:O). From all worksheets in the master but my code is only copying column E? I am really new to Vba and not sure of the syntax to copy mutiple columns. Thanks for the help.

Sub Master()

Dim ws As Worksheet
Application.ScreenUpdating = False
Sheets("Master").Activate

For Each ws In Worksheets
If ws.Name <> "Master" Then
ws.Range("E:O").Copy
ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)

End If

Next ws

End Sub



 
Upvote 0
@Mel2016,
Code:
Dim lastRow As Long
lastRow = ws.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
ws.Range("E1:O" & lr).Copy ActiveSheet.Cells(Rows.Count, 1).End(xlUp)(2)
Put the Dim statement at the top with your other declaration and insert the lastRow line after the For Each line. Substitute the copy line for the one you now have and the paste line.

We could both get in trouble for jumping in on this thread.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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