oldmanwilly
Board Regular
- Joined
- Feb 24, 2016
- Messages
- 221
Hi
I have a userform with 10 checkboxes, and I want the user to be able to select a box and then either click a button that says a4 or a3 and once clicked will print the selected checkboxes (which correspond to sheet tabs) in a4 or a3 and the printarea will resize based on what they enter in the tables in the sheets.
I tried this code and used a named range for each sheet to count the last row in the sheets for the printarea.
any other information you need let me know thanks again.
code for print area
I have a userform with 10 checkboxes, and I want the user to be able to select a box and then either click a button that says a4 or a3 and once clicked will print the selected checkboxes (which correspond to sheet tabs) in a4 or a3 and the printarea will resize based on what they enter in the tables in the sheets.
I tried this code and used a named range for each sheet to count the last row in the sheets for the printarea.
any other information you need let me know thanks again.
Code:
Private Sub CommandButton1_Click()
Dim page1 As Sheets
Dim page2 As Sheets
Dim page3 As Sheets
Dim page4 As Sheets
Dim page5 As Sheets
Dim page6 As Sheets
Dim page7 As Sheets
Dim page8 As Sheets
Dim page9 As Sheets
Dim page10 As Sheets
Dim pageIndexbox As Sheets
Dim pageStartbox As Sheets
Dim pageIntroductionBox As Sheets
Dim pageguidancebox As Sheets
Dim pageDatainputtemplateBox As Sheets
Dim pageSummary1Box As Sheets
Dim pageSummary2Box As Sheets
Dim pageSummary3box As Sheets
Dim pagelistofmetricsBox As Sheets
Set page1 = Sheets("Index")
Set page2 = Sheets("Start")
Set page3 = Sheets("Introduction")
Set page4 = Sheets("Guidance")
Set page5 = Sheets("dATA INPUT TEMPLATE")
Set page6 = Sheets("Summary 1")
Set page7 = Sheets("Summary 2")
Set page8 = Sheets("Summary 3")
Set page9 = Sheets("List of Metrics")
'Set page10 = Sheets("Metadata")
pageIndexbox = page1
pageStartbox = page2
pageIntroductionBox = page3
pageguidancebox = page4
pageDatainputtemplateBox = page5
pageSummary1Box = page6
pageSummary2Box = page7
pageSummary3box = page8
pagelistofmetricsBox = page9
For Each CheckBox In UserForm1
where CheckBox.Value = True
Sheets("page" & CheckBox.Name).Activate
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintArea = ActiveSheet.Name & 1
.FitToPagesWide = 1
.FitToPagesTall = False
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PaperSize = xlPaperA4
ActiveSheet.PrintOut
Next
Next checkboxbox
code for print area
Code:
=OFFSET(INDEX!A1,0,0,COUNTA(INDEX!A:A)-1,COUNTA(INDEX!1:1))