Consolidating dynamic no. of worksheets & excluding some

MarkVMcCullagh

Board Regular
Joined
Oct 22, 2002
Messages
72
I have a workbook that will contain 20-35 worksheets that will need consolidating into 1 worksheet called "Total" within the same workbook. The worksheets will all have an identical layout but the number of worksheets needing consolidating will vary upwards or downwards.

However there will be several worksheets within the workbook which I do not want consolidated named "ExcludeMe1", "ExcludeMe2" and "ExcludeMe3".

I found the following code on the site and was wondering how I could modify it to exclude certain worksheets.

Sub CombineData()
' Written by Barrie Davidson
Dim WS As Worksheet
Dim Temp As Integer

Application.ScreenUpdating = False
Temp = 1
For Each WS In ActiveWorkbook.Sheets
If WS.Name <> "Amendments" Then
If Temp = 1 Then
WS.Range("A45:K" & WS.Range("A65536").End(xlUp).Row).Copy _
Destination:=Sheets("Amendments"). _
Range("A5")
Else
WS.Range("A45:K" & WS.Range("A65536").End(xlUp).Row).Copy _
Destination:=Sheets("Amendments"). _
Range("A65536").End(xlUp).Offset(1, 0)
End If
Temp = 0
End If
Next WS
Application.ScreenUpdating = True
End Sub

Thanks in Advance
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Modify this line of code:
If WS.Name <> "Amendments" Then

To this:
If WS.Name <> "Amendments" Or WS.Name <> "ExcludeMe1" Or WS.Name <> "ExcludeMe2" Or WS.Name <> "ExcludeMe3" Then

Have a great day,
Stan
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

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