ransomedbyfire
Board Regular
- Joined
- Mar 9, 2011
- Messages
- 121
I've got a userform with something like 9 checkboxes on it that each represent a worksheet to be selected for printing. For some reason, the code seems to be "remembering" the last tab I told it to print and including it in the new print list.
Here is the code that runs with the userform is opened:
And here is one of the codes that add each checked sheetname to the printing queue.
And, finally, here is the code that runs when the Print button is clicked.
End Sub
Here is the code that runs with the userform is opened:
Code:
Sub print_custom()
Sheet12.Range("d:d").ClearContents
UserForm1.Cs.Value = False
UserForm1.Es.Value = False
UserForm1.Ex.Value = False
UserForm1.Ey.Value = False
UserForm1.In.Value = False
UserForm1.J.Value = False
UserForm1.Ka.Value = False
UserForm1.Od.Value = False
UserForm1.Sx.Value = False
UserForm1.Sy.Value = False
UserForm1.Select_All.Value = False
UserForm1.Show
Code:
Private Sub Cs_Click()
sheeti = Sheets("Cs").Index
Set clicked = Sheet12.Range("d:d").Find(what:=sheeti)
If Not clicked Is Nothing Then
findrow = Sheet12.Range("d:d").Find(what:=sheeti).Row
Sheet12.Range("d" & findrow).Delete shift:=xlUp
GoTo exitsub
End If
firstblank = Sheet12.Range("D:D").Find(what:="").Row
If Sheet12.Range("d1") = "" Then
firstblank = 1
End If
Sheet12.Cells(firstblank, 4) = sheeti
exitsub:
End Sub
Code:
Private Sub Print_Button_Click()
UserForm1.Hide
Application.Wait (100)
If Sheet12.Range("d1") = "" Then
MsgBox "You have not selected any sheets to print. Please hit the ""Print Custom"" button and select at least one sheet to print."
GoTo exitsub
End If
lastrow = Sheet12.Range("d:d").Find(what:="").Row - 1
If lastrow = 11 Then
lastrow = 10
End If
Sheets("Cs").Visible = True
Sheets(Sheet12.Cells(1, 4).Value).Select
For Row = 1 To lastrow
sheeti = Sheet12.Cells(Row, 4).Value
ActiveWorkbook.Sheets(sheeti).Select False
MsgBox Sheets(sheeti).Name
Next Row
ActiveWindow.SelectedSheets.PrintOut preview:=True
Sheets("Cs").Visible = False
ThisWorkbook.Sheets("io").Select
exitsub:
End Sub