Amend Macro to Exclude Certain Worsheets

welshraz

New Member
Joined
Apr 29, 2016
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Afternoon,

I have a code that has been working really well, compiling data from several sheets into one master sheet at the click of a button. Now, some pesky, sticky fingered colleague has added an additional sheet that I do not want included in this as it does not contain the same fields/headers etc. This is the code:

Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
If var = 0 Then Sheets.Add(Before:=Sheets(1)).Name = "Master" Else
Sheets("Master").Move Before:=Sheets(1)
Sheets(2).Activate
Sheets(2).Range(Range("a3"), Range("A3").End(xlToRight)).Copy
Sheets(1).Activate
Sheets("Master").Paste Destination:=Range("a3")
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name Then
With Sh
.Range("A3:M" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
Selection.Columns.AutoFit
End Sub

Can this be amended to exclude any sheet with the name 'SPO'? Many thanks.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
There's quite a bit that can be cleaned up in that macro, but for now, just change this line:

VBA Code:
If Sh.Name <> ActiveSheet.Name Then

to

VBA Code:
If Sh.Name <> ActiveSheet.Name and Sh.Name <> "SPO" Then
 
Upvote 0
Solution

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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