welshraz
New Member
- Joined
- Apr 29, 2016
- Messages
- 39
- Office Version
- 365
- Platform
- 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.
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.