A previous thread I answered, I was looping through the sheets, and if the sh.name<>w1.name or sh.name<>w2.name or sh.name<>w3.name then
The code would not ignore the w1,w2,w3 worksheets, I had to use if then for each worksheet.
If Or code
Sub MakeItSo()
Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
Dim lastColumn As Long, sh As Worksheet, s As String
Dim lastRow As Long
Dim rng As Range
Set w1 = Sheets("Group1")
Set w2 = Sheets("Group2")
Set w3 = Sheets("Group3")
For Each sh In Sheets
If sh.Name <> w1.Name Or sh.Name <> w2.Name Or sh.Name <> w3.Name Then
s = Left(sh.Name, 1)
With sh
lastColumn = .Cells(1, Columns.Count).End(xlToLeft).Column
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng = .Range(.Cells(1, 1), .Cells(lastRow, lastColumn))
rng.Copy Sheets("Group" & s).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
End If
Next sh
End Sub
If then Code
Sub MakeItSeveralIfs()
Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
Dim lastColumn As Long, sh As Worksheet, s As String
Dim lastRow As Long
Dim rng As Range
Set w1 = Sheets("Group1")
Set w2 = Sheets("Group2")
Set w3 = Sheets("Group3")
For Each sh In Sheets
If sh.Name <> w1.Name Then
If sh.Name <> w2.Name Then
If sh.Name <> w3.Name Then
s = Left(sh.Name, 1)
With sh
lastColumn = .Cells(1, Columns.Count).End(xlToLeft).Column
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng = .Range(.Cells(1, 1), .Cells(lastRow, lastColumn))
rng.Copy Sheets("Group" & s).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
End If
End If
End If
Next sh
End Sub
I'm sure I have gotten this to work before.
Check out the attached.
Bookmarks