Hi All,
I have an excel workbook with 16 worksheets. Only one sheet is visible at a time for the user to fill out and then they click a button to go back to the main menu sheet. On the main menu sheet I would like a button to do the following:
1) print hidden worksheets - 10 of them, not all 16
2) on the sheets being printed hide specific rows based on a cell being empty when printing i.e. if cell C6 is empty then hide row 6 (it will not be the same row in all sheets)
3) number the pages in order when printing. Currently the sheets are in order of how I want them to print but the page numbers in the footer print page ? of ? for each sheet not for the number of sheets being printed altogether.
I tried the below but it printed all hidden sheets and didn't hide the rows with an empty cell (I only tried the empty cell macro for one sheet to test it). I changed the color of the tabs I didn't want printed to see if the below macro would work, it does on its own but not in conjunction with the other two.
Is what I'm asking impossible or is there a way of doing this?
The users filling out the sheets are far from excel experts and everything except the cells they need to fill out will be locked. So they won't be able to hide rows manually or print manually. Everything needs to be done by the click of a button.
Sub RunAllMacros()
Procedure1
Procedure2
Procedure3
End Sub
'print hidden sheets
Sub Procedure1()
' jiuk - infomation(s)
'xlSheetVisible = -1
'xlSheetHidden = 0
'xlSheetVeryHidden = 2
Dim mySheets As Excel.Worksheet
For Each mysheet In ThisWorkbook.Worksheets
If mysheet.Visible = 0 Or mysheet.Visible = 2 Then
If mysheet.Visible = 0 Then
With mysheet
.Visible = -1
.PrintOut
.Visible = 0
End With
End If
If mysheet.Visible = 2 Then
With mysheet
.Visible = -1
.PrintOut
.Visible = 2
End With
End If
End If
Next
End Sub
'print non coloured tabs
Sub Procedure2()
Application.ScreenUpdating = False
For Each Z In ThisWorkbook.Worksheets
If Z.Tab.ColorIndex = xlColorIndexNone Then
Z.PrintOut copies = 1
End If
Next
End Sub
'hide rows based on empty cell
Sub Procedure3()
Dim rw As Long
Dim rng As Range
Dim cell As Range
Application.ScreenUpdating = False
Set rng = Sheets("Sheet5").Range("C6:C14")
With rng.Columns(1)
For Each cell In rng
If Application.WorksheetFunction.CountA( _
.Parent.Cells(cell.Row, 1).Range("C6:C6")) = " " Then _
.Parent.Rows(cell.Row).Hidden = True
Next cell
.Parent.PrintOut
.EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub
I have an excel workbook with 16 worksheets. Only one sheet is visible at a time for the user to fill out and then they click a button to go back to the main menu sheet. On the main menu sheet I would like a button to do the following:
1) print hidden worksheets - 10 of them, not all 16
2) on the sheets being printed hide specific rows based on a cell being empty when printing i.e. if cell C6 is empty then hide row 6 (it will not be the same row in all sheets)
3) number the pages in order when printing. Currently the sheets are in order of how I want them to print but the page numbers in the footer print page ? of ? for each sheet not for the number of sheets being printed altogether.
I tried the below but it printed all hidden sheets and didn't hide the rows with an empty cell (I only tried the empty cell macro for one sheet to test it). I changed the color of the tabs I didn't want printed to see if the below macro would work, it does on its own but not in conjunction with the other two.
Is what I'm asking impossible or is there a way of doing this?
The users filling out the sheets are far from excel experts and everything except the cells they need to fill out will be locked. So they won't be able to hide rows manually or print manually. Everything needs to be done by the click of a button.
Sub RunAllMacros()
Procedure1
Procedure2
Procedure3
End Sub
'print hidden sheets
Sub Procedure1()
' jiuk - infomation(s)
'xlSheetVisible = -1
'xlSheetHidden = 0
'xlSheetVeryHidden = 2
Dim mySheets As Excel.Worksheet
For Each mysheet In ThisWorkbook.Worksheets
If mysheet.Visible = 0 Or mysheet.Visible = 2 Then
If mysheet.Visible = 0 Then
With mysheet
.Visible = -1
.PrintOut
.Visible = 0
End With
End If
If mysheet.Visible = 2 Then
With mysheet
.Visible = -1
.PrintOut
.Visible = 2
End With
End If
End If
Next
End Sub
'print non coloured tabs
Sub Procedure2()
Application.ScreenUpdating = False
For Each Z In ThisWorkbook.Worksheets
If Z.Tab.ColorIndex = xlColorIndexNone Then
Z.PrintOut copies = 1
End If
Next
End Sub
'hide rows based on empty cell
Sub Procedure3()
Dim rw As Long
Dim rng As Range
Dim cell As Range
Application.ScreenUpdating = False
Set rng = Sheets("Sheet5").Range("C6:C14")
With rng.Columns(1)
For Each cell In rng
If Application.WorksheetFunction.CountA( _
.Parent.Cells(cell.Row, 1).Range("C6:C6")) = " " Then _
.Parent.Rows(cell.Row).Hidden = True
Next cell
.Parent.PrintOut
.EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub