Merge data from all bar 2 sheets

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
433
Dear All

I am trying to copy data from all sheets in one workbook but NOT copy from the HOME sheet and the Prog_Dep sheet, here is my code it copies but also copies these two sheets that I do not want it too.

Sub CombineData()
Dim ws As Worksheet

For Each ws In Worksheets

If ws.Name <> ("Prog_Dep") Or ws.Name <> ("HOME") Then ws.Select


Range("A1:J25").Copy
Sheets("Prog_Dep").Select

Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste



Next ws


End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi there. Try this:
Code:
Sub CombineData()
Dim ws As Worksheet

For Each ws In Worksheets

If ws.Name <> ("Prog_Dep") And ws.Name <> ("HOME") Then
    ws.Select
    Range("A1:J25").Copy
    Sheets("Prog_Dep").Select
    
    Range("A65536").End(xlUp).Offset(1, 0).Select
    ActiveSheet.Paste
End If
Next ws
End Sub
 
Last edited:
Upvote 0
Just as a query how many And's can you use ? for example if I have 5 sheets I want it to ignore do I just repeat the AND code?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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