Hello,
Can someone please help me and tell me what I am doing wrong?
Private Sub CommandButton1_Click()
Sub test()
Dim rng As Range
Dim wks As Worksheet
For Each rng In Sheets("ToC").Range("B3:B15")
If Trim(rng.Value) <> "" Then
On Error Resume Next
Set wks = Nothing
Set wks = Sheets(rng.Value)
On Error GoTo 0
If wks Is Nothing Then
MsgBox "Sheet " & rng.Value & " does not exist"
Else
wks.PrintOut
End If
End If
Next rng
End Sub
End Sub
The ToC is has the list of worksheet names to be printed. B3 to B15.
Should I be removing the Sub test() ??
Can someone please help me and tell me what I am doing wrong?
Private Sub CommandButton1_Click()
Sub test()
Dim rng As Range
Dim wks As Worksheet
For Each rng In Sheets("ToC").Range("B3:B15")
If Trim(rng.Value) <> "" Then
On Error Resume Next
Set wks = Nothing
Set wks = Sheets(rng.Value)
On Error GoTo 0
If wks Is Nothing Then
MsgBox "Sheet " & rng.Value & " does not exist"
Else
wks.PrintOut
End If
End If
Next rng
End Sub
End Sub
The ToC is has the list of worksheet names to be printed. B3 to B15.
Should I be removing the Sub test() ??