Compiling Worksheets from the Same Workbook

Alex89

New Member
Joined
May 30, 2019
Messages
34
Hi Everyone,

I'm trying to compile 6 worksheets from the same workbook, into 2 separate worksheets. In this instance I am trying to copy data from the 3 publisher content tabs into a master sheet, but I am getting an error with this line of code

For Each ws In ThisWorkbook.Worksheets("Publisher - Content", "Publisher - Content (2)", "Publisher - Content (3)")


Sub Combined()


Dim ws As Worksheet
Dim shtMaster As Worksheet
Dim rTargetLastCell As Range
Dim rSourceLastCell As Range


Set shtMaster = ThisWorkbook.Worksheets("Master Data")


'Cycle through each worksheet in the workbook.
'NB: Worksheets exclude chart sheets and macro sheets.
For Each ws In ThisWorkbook.Worksheets("Publisher - Content", "Publisher - Content (2)", "Publisher - Content (3)")
Select Case ws.Name
Case "Master Data"
'Do Nothing
Case Else
'Find the last cell containing data in the two sheets.
Set rTargetLastCell = LastCell(ThisWorkbook.Worksheets("Master Data"))
Set rSourceLastCell = LastCell(ws)


'Copy and paste the relevant data.
With ws
.Range(.Cells(3, 1), rSourceLastCell).Copy _
Destination:=shtMaster.Cells(rTargetLastCell.Row + 1, 1)
End With
End Select
Next ws


End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Haven't looked at the rest of your code, but try changing the errant line to this:
Code:
For Each ws In ThisWorkbook.Worksheets(Array("Publisher - Content", "Publisher - Content (2)", "Publisher - Content (3)"))
 
Upvote 0
Hi & welcome to MrExcel.
Try
Code:
For Each ws In ThisWorkbook.Worksheets(Array("Publisher - Content", "Publisher - Content (2)", "Publisher - Content (3)"))
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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