Keep hidden rows hidden when filtered

RattlingCarp3048

Board Regular
Joined
Jan 12, 2022
Messages
166
Office Version
  1. 365
Platform
  1. Windows
Is there a way to keep hidden rows hidden when filtering/unfiltering?

I have a code that will hide rows when certain criteria is met. However, when we use basic filter to examine the visible rows we noticed the hidden rows are now visible. Is there a way to keep them hidden regardless of the basic filter being used?
 
i took a slightly different approach. maybe this would be a new thread (?)

i created the helper column you suggested then made an event procedure so that when the workbook opens it will automatically filter the rows to hide the ones in questions. my only question would be how to make it more dynamic. the helper column will periodically change positions as i made it the last column of the entire spreadsheet.

Private Sub Workbook_Open()
Rows("2:2").Select
Selection.AutoFilter
Range("A2").Select
Selection.End(xlToRight).Select
ActiveSheet.Range("$A$2:$ER$467").AutoFilter Field:=148, Criteria1:="No"
Range("C2").Select
End Sub
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Are there always headers in row 1 that we can use to dynamically find this last column?
 
Upvote 0
Try something like this:
VBA Code:
Private Sub Workbook_Open()

    Dim lc As Long
    Dim rng As Range
   
'   Find last column on row 2 with data
    lc = Cells(2, Columns.Count).End(xlToLeft).Column
   
'   Build range to check
    Set rng = Range(Cells(2, 1), Cells(467, lc))
   
'   Filter
    Rows("2:2").AutoFilter
    ActiveSheet.rng.AutoFilter Field:=lc, Criteria1:="No"

End Sub
 
Last edited:
Upvote 0
Try something like this:
VBA Code:
Private Sub Workbook_Open()

    Dim lc As Long
    Dim rng As Range
   
'   Find last column on row 2 with data
    lc = Cells(2, Columns.Count).xlToLeft.Column
   
'   Build range to check
    Set rng = Range(Cells(2, 1), Cells(467, lc))
   
'   Filter
    Rows("2:2").AutoFilter
    ActiveSheet.rng.AutoFilter Field:=lc, Criteria1:="No"

End Sub
object doesnt support this property or method

debug highlighted lc = Cells(2, Columns.Count).xlToLeft.Column
 
Upvote 0
object doesnt support this property or method

debug highlighted lc = Cells(2, Columns.Count).xlToLeft.Column
Sorry, I had a typo. It should be:
VBA Code:
    lc = Cells(2, Columns.Count).End(xlToLeft).Column

I went back and updated the code to reflect that.
 
Upvote 0
Sorry, I had a typo. It should be:
VBA Code:
    lc = Cells(2, Columns.Count).End(xlToLeft).Column

I went back and updated the code to reflect that.
same error ActiveSheet.rng.AutoFilter Field:=lc, Criteria1:="No"
 
Upvote 0
OK, try this:
VBA Code:
Private Sub Workbook_Open()

    Dim lc As Long
    Dim rng As Range
   
'   Find last column on row 2 with data
    lc = Cells(2, Columns.Count).End(xlToLeft).Column
   
'   Build range to check
    Set rng = Range(Cells(2, 1), Cells(467, lc))
   
'   Filter
    rng.AutoFilter
    rng.AutoFilter Field:=lc, Criteria1:="No"

End Sub
 
Upvote 0
OK, try this:
VBA Code:
Private Sub Workbook_Open()

    Dim lc As Long
    Dim rng As Range
  
'   Find last column on row 2 with data
    lc = Cells(2, Columns.Count).End(xlToLeft).Column
  
'   Build range to check
    Set rng = Range(Cells(2, 1), Cells(467, lc))
  
'   Filter
    rng.AutoFilter
    rng.AutoFilter Field:=lc, Criteria1:="No"

End Sub
it seems to do the job! an entirely different approach to what should be a simple fix on the user's behalf. so the final solution was a conjunction of our two thoughts. I added a helper column at the very end of the document which is completely out out sight. it has a formula to categorize the rows into yes/no criteria. then with your help, made an event procedure to auto filter the helper column to No everytime the workbook opens. it solves all the issues we were having with the basic filter and still does not show the "hidden" rows when trying to print.

Thanks a ton!!
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,189
Members
449,213
Latest member
Kirbito

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