AndrewGKenneth

Board Regular
Joined
Aug 6, 2018
Messages
59
Hi there,

I am having a problem with trying to get my spreadsheet to filter automatically. To explain my problem I have a spreadsheet ("Sheet2") and in column A is the value that will be filtered. In column A i want only the values that are "TRUE" to show. For example, if A1 is True the values in A2 and A3 will show, if A1 is not True A2 and A3 will be filtered.

The problem i am having is that when True values are updated in column A the filter is not automatically updating. The code

Private Sub Worksheet_Change(ByVal Target As Range)
Activesheet.Autofilter.Applyfilter
End Sub

Does not work because it only updates the cells that are hidden and does not automatically refresh the TRUE values that will be visible. Can anyone help please?
 

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.
Hi,
bit of a guess but assuming that you have already applied the filter for your range & just want to update it then try this update to your code & see if this does what you want

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Me.AutoFilterMode Then Me.ShowAllData: Me.AutoFilter.ApplyFilter
End Sub

Note that the change event does not trigger if your values are being changed by formula.

Dave
 
Last edited:
Upvote 0
Ah that will be why then the data being entered into Cell Range A is from a formula, so will not be affecting the change trigger. Is there anyway around this? Thanks Dave
 
Upvote 0
Ah that will be why then the data being entered into Cell Range A is from a formula, so will not be affecting the change trigger. Is there anyway around this? Thanks Dave

you can try using the Calculate Event however, this does not have target argument to determine which cell has change but there are ways to manage this.

Code:
Private Sub Worksheet_Calculate()
    With Me.Cells(1, 1)
        If .ID <> .Value Then
            .ID = .Value
            If Me.AutoFilterMode Then Me.ShowAllData: Me.AutoFilter.ApplyFilter
        End If
    End With
End Sub

Solution uses Range.ID property as a place holder to compare the cells value & if this changes, run your line code.

Hope Helpful

Dave
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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