I would like to unhide the row after printing

itsgrady

Board Regular
Joined
Sep 11, 2022
Messages
132
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
I’m not able to add the code to unhide all rows after printing. It keeps saying broken code. I would like unhide all rows after printing. Thanks for the help.

Sub Hide_Unhide_Rows()

Dim sPass As String

sPass = InputBox("Hello Grady, I hope you enjoy the print job!", "Password")

If sPass = "again" Then ' Your password is "again"

Else

MsgBox " Incorrect Password, Try Again. "

Exit Sub



End If

ActiveSheet.Unprotect

For Each cell In Range("B23:B67")

If cell.Value = "14" Then cell.EntireRow.Hidden = True

If cell.Value = "<14" Then cell.EntireRow.Hidden = False

Next cell

ActiveWindow.SmallScroll Down:=-16

Application.Goto Reference:="Print_Area"

ActiveWindow.SmallScroll Down:=-62

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _

IgnorePrintAreas:=False

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _

False, AllowSorting:=True, AllowFiltering:=True

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try:

Rich (BB code):
Sub Hide_Unhide_Rows()
  Dim sPass As String
  Dim cell As Range

  sPass = InputBox("Hello Grady, I hope you enjoy the print job!", "Password")
  If sPass = "again" Then ' Your password is "again"
  Else
    MsgBox " Incorrect Password, Try Again. "
    Exit Sub
  End If
 
  ActiveSheet.Unprotect
  For Each cell In Range("B23:B67")
    If cell.Value = "14" Then cell.EntireRow.Hidden = True
    If cell.Value < "14" Then cell.EntireRow.Hidden = False    'I'm assuming it must be less than 14, so the < operator goes outside the quotes.
  Next cell
  Application.Goto Reference:="Print_Area"
  ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
 
  Range("23:67").EntireRow.Hidden = False           'To make the range of rows visible
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, _
    AllowSorting:=True, AllowFiltering:=True
 
End Sub
 
Upvote 1
Solution
Try:

Rich (BB code):
Sub Hide_Unhide_Rows()
  Dim sPass As String
  Dim cell As Range

  sPass = InputBox("Hello Grady, I hope you enjoy the print job!", "Password")
  If sPass = "again" Then ' Your password is "again"
  Else
    MsgBox " Incorrect Password, Try Again. "
    Exit Sub
  End If
 
  ActiveSheet.Unprotect
  For Each cell In Range("B23:B67")
    If cell.Value = "14" Then cell.EntireRow.Hidden = True
    If cell.Value < "14" Then cell.EntireRow.Hidden = False    'I'm assuming it must be less than 14, so the < operator goes outside the quotes.
  Next cell
  Application.Goto Reference:="Print_Area"
  ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
 
  Range("23:67").EntireRow.Hidden = False           'To make the range of rows visible
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, _
    AllowSorting:=True, AllowFiltering:=True
 
End Sub
Thank you very much your help. I appreciate the other tweaks to code as well. The code worked perfectly.

I am surprise that only row at a time is hidden and you can watch the process. Seems like it would do it a lot faster.

Thanks again for your time and for your expertise.
 
Upvote 0
I am surprise that only row at a time is hidden and you can watch the process. Seems like it would do it a lot faster.
I don't know exactly what you mean, but try with turn off screen updating:

VBA Code:
Sub Hide_Unhide_Rows()
  Dim sPass As String
  Dim cell As Range

  sPass = InputBox("Hello Grady, I hope you enjoy the print job!", "Password")
  If sPass = "again" Then ' Your password is "again"
  Else
    MsgBox " Incorrect Password, Try Again. "
    Exit Sub
  End If
 
Application.ScreenUpdating = False

  ActiveSheet.Unprotect
  For Each cell In Range("B23:B67")
    If cell.Value = "14" Then cell.EntireRow.Hidden = True
    If cell.Value < "14" Then cell.EntireRow.Hidden = False    'I'm assuming it must be less than 14, so the < operator goes outside the quotes.
  Next cell
  Application.Goto Reference:="Print_Area"
  ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
 
  Range("23:67").EntireRow.Hidden = False           'To make the range of rows visible
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, _
    AllowSorting:=True, AllowFiltering:=True
 
Application.ScreenUpdating = True

End Sub
 
Upvote 0
I don't know exactly what you mean, but try with turn off screen updating:

VBA Code:
Sub Hide_Unhide_Rows()
  Dim sPass As String
  Dim cell As Range

  sPass = InputBox("Hello Grady, I hope you enjoy the print job!", "Password")
  If sPass = "again" Then ' Your password is "again"
  Else
    MsgBox " Incorrect Password, Try Again. "
    Exit Sub
  End If
 
Application.ScreenUpdating = False

  ActiveSheet.Unprotect
  For Each cell In Range("B23:B67")
    If cell.Value = "14" Then cell.EntireRow.Hidden = True
    If cell.Value < "14" Then cell.EntireRow.Hidden = False    'I'm assuming it must be less than 14, so the < operator goes outside the quotes.
  Next cell
  Application.Goto Reference:="Print_Area"
  ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
 
  Range("23:67").EntireRow.Hidden = False           'To make the range of rows visible
  ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, _
    AllowSorting:=True, AllowFiltering:=True
 
Application.ScreenUpdating = True

End Sub
Thanks for the screen updating code. It made the process a lot better.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top