I searched the site and found the VBA code to select worksheets by tab color. I then added the code to print the selected sheets. However, it's getting stuck on 'Next ws' before printing. Can anyone help with what I'm missing?
The macro is as follows:
Sub SelectByTabColor()
Sheets("Account Summary").Select
Calculate
ActiveWorkbook.Save
Sheets("Account Summary").Select
Dim wsNames() As String
Dim wsColor() As Integer
Dim ws As Worksheet
Dim ind As Integer
ReDim wsNames(0)
ReDim wsColor(0)
wsNames(0) = ActiveSheet.Name
wsColor(0) = ActiveSheet.Tab.ColorIndex
For Each ws In ThisWorkbook.Sheets
If ws.Tab.ColorIndex = wsColor(0) And ws.Visible = xlSheetVisible Then
ReDim Preserve wsNames(UBound(wsNames) + 1)
ReDim Preserve wsColor(UBound(wsColor) + 1)
wsNames(UBound(wsNames)) = ws.Name
wsColor(UBound(wsColor)) = ws.Tab.ColorIndex
End If
Next ws
Sheets(wsNames).Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("Account Summary").Select
End Sub
The macro is as follows:
Sub SelectByTabColor()
Sheets("Account Summary").Select
Calculate
ActiveWorkbook.Save
Sheets("Account Summary").Select
Dim wsNames() As String
Dim wsColor() As Integer
Dim ws As Worksheet
Dim ind As Integer
ReDim wsNames(0)
ReDim wsColor(0)
wsNames(0) = ActiveSheet.Name
wsColor(0) = ActiveSheet.Tab.ColorIndex
For Each ws In ThisWorkbook.Sheets
If ws.Tab.ColorIndex = wsColor(0) And ws.Visible = xlSheetVisible Then
ReDim Preserve wsNames(UBound(wsNames) + 1)
ReDim Preserve wsColor(UBound(wsColor) + 1)
wsNames(UBound(wsNames)) = ws.Name
wsColor(UBound(wsColor)) = ws.Tab.ColorIndex
End If
Next ws
Sheets(wsNames).Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("Account Summary").Select
End Sub