Automatically hide rows with "FALSE" values

PapaRainman

New Member
Joined
Dec 19, 2019
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys!

Needing your help with this.

What I would want to do is to:

1. Hide the rows that has the value of "FALSE" as a result of an IF and VLOOKUP formula.
2. Select the cells and set the print area.
3. Print as PDF - I am already good with this :D

Thank you.
 

Attachments

  • Image.png
    Image.png
    38.4 KB · Views: 16

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
welcome to the forum

The image in post#1 does not include row & column identifiers
- amend "F" if necessary

Column F.jpg



VBA Code:
Sub HideRows()
    Const X = "F"
    Dim r As Long, Rng As String
    Rng = "@"
    On Error Resume Next
    For r = 2 To Cells(Rows.Count, X).End(xlUp).Row
        If Cells(r, X).Value <> CVErr(xlErrNA) Then If Cells(r, X) = "False" Then Rng = Rng & "," & X & r
    Next r
    Hide Cells, False
    If Not Rng = "@" Then Hide Range(Replace(Rng, "@,", "")), True
End Sub

Private Sub Hide(aRange As Range, HideIt As Boolean)
    aRange.EntireRow.Hidden = HideIt
End Sub
 
Upvote 0
Hi Yongle,

Thank you for your reply. I have included the image with the identifiers.

Also, here is my code as of now. I'm having trouble where should I place your code.

VBA Code:
Sub SelectAndCreatePDF()
Dim i As Integer, PDFindex As Integer
    Dim PDFfileName As String
    Dim LR As Long, cell As Range, rng As Range

    Range("A1:H12").Select
      ActiveSheet.PageSetup.Orientation = xlLandscape
      ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF
      ActiveSheet.PageSetup.PrintArea = "A1:H12"
      With Application.FileDialog(msoFileDialogSaveAs)
      
      PDFindex = 0
        For i = 1 To .Filters.Count
            If InStr(VBA.UCase(.Filters(i).Description), "PDF") > 0 Then PDFindex = i
        
        Next
        .Title = "Save sheet as PDF"
        .InitialFileName = PDFName
        .FilterIndex = PDFindex
        
        If .Show Then
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.SelectedItems(1), _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
        End If
      
End With

End Sub

Appreciate your help with this.
 

Attachments

  • ScreenHunter 03.png
    ScreenHunter 03.png
    46.6 KB · Views: 7
Upvote 0
welcome to the forum

The image in post#1 does not include row & column identifiers
- amend "F" if necessary

View attachment 2580


VBA Code:
Sub HideRows()
    Const X = "F"
    Dim r As Long, Rng As String
    Rng = "@"
    On Error Resume Next
    For r = 2 To Cells(Rows.Count, X).End(xlUp).Row
        If Cells(r, X).Value <> CVErr(xlErrNA) Then If Cells(r, X) = "False" Then Rng = Rng & "," & X & r
    Next r
    Hide Cells, False
    If Not Rng = "@" Then Hide Range(Replace(Rng, "@,", "")), True
End Sub

Private Sub Hide(aRange As Range, HideIt As Boolean)
    aRange.EntireRow.Hidden = HideIt
End Sub

I forgot to quote your reply. Sorry.
 
Upvote 0
VBA Code:
If .Show Then
   Call HideRows
   ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.SelectedItems(1), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
 
Upvote 0
VBA Code:
If .Show Then
   Call HideRows
   ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.SelectedItems(1), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If


Thank you so much Yongle! I should have created a separate button instead to do hide rows. I'm getting compiled error when merging it.

Also, if I am planning to make a reset button to unhide the rows, can you please point me to the right direction?
 
Upvote 0
I am planning to make a reset button to unhide the rows, can you please point me to the right direction?
This makes all rows visible
VBA Code:
 ActiveSheet.Cells.EntireRow.Hidden = False
 
Upvote 0
@PapaRainman
For future reference while we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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