Automatically filter rows by cell value

mtdeilus

New Member
Joined
Aug 26, 2014
Messages
11
Currently I'm working with a data table that I've built in True/False IF function in columns D and K. This allows the user to have 2 text boxes at the top of the table, which filter the table based on user entry.

I would like VBA to automatically remove the "false" rows which come back on value. Currently this is the VBA code I'm working with, which only is working for column K. I would like to have both of the rows work at once. I appreciate any help!

Matt

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
For Each c In Range("D7:D200")
If c.Value = False Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next c
Dim d As Range
For Each d In Range("K7:K200")
If d.Value = False Then
d.EntireRow.Hidden = True
Else
d.EntireRow.Hidden = False
End If
Next d
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.
What you are doing is hiding your unwanted rows in "D" and then unhiding them again when the macro continues to column "K". So to clarify if either cell contains false you want the row hidden?
 
Upvote 0
Untested so try it on copied workbook first. Slight change to yours. Probably better way but vba not my strong point.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range

Cells.EntireRow.Hidden=False
    For Each c In Range("D7:D200")
        If c.Value = "False" Then
            c.EntireRow.Hidden = True
            Else: End If
    Next c
  Dim d As Range
    For Each d In Range("K7:K200")
        If d.Value = "False" Then
            d.EntireRow.Hidden = True
            Else: End If
    Next d
End Sub
 
Last edited:
Upvote 0
Just to follow up on this, I have my left two columns with 4 rows of search filters on my worksheet. When the rows automatically filter, is there any way to keep column A and B from moving? Freeze panes does not seem to work.
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,208
Members
453,151
Latest member
Lizamaison

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