Print Rows based on value of cell B13:B53

codyssey

New Member
Joined
Oct 15, 2015
Messages
39
Hello everyone:rolleyes:

I have an order form with multiple options listed. In cells B13:B53 I have checkboxes (linked to those cells). Some rows instead of checkboxes, I have a quantity set to "0" by default. This sheet is protected.

I would like it to print only the rows that have TRUE in column B or a number that is greater than 0. The code I have is not working:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
     
    Select Case Worksheets("Sheet2").Range("B13:B53").Text
    Case "FALSE", "0"
        Worksheets("Sheet2").Rows("B13:B53").EntireRow.Hidden = True
    End Select
    Application.Dialogs(xlDialogPrint).Show
End Sub

Any input is appreciated. Been banging my head against the wall trying to get this working :rolleyes::rolleyes:
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Sub HideTrueOrGT0InColumnB()

    Dim wks As Worksheet
    Dim rng As Range
    Dim rngCell As Range
    
    Set wks = Worksheets("Sheet2")
    Set rng = wks.Range("B13:B53")
    
    For Each rngCell In rng
        Debug.Print rngCell.Address, rngCell.Value
        If rngCell.Value = True Or rngCell.Value > 0 Then
            rngCell.EntireRow.Hidden = True
        Else
            rngCell.EntireRow.Hidden = False
        End If
    Next
    
    Set wks = Nothing
    Set rng = Nothing
    
End Sub

Sub UnHideAllRows()
    Cells.EntireRow.Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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