Autofilter based on Dynamic Cell Values (Pivot Table)

quixter

New Member
Joined
Nov 1, 2015
Messages
20
Hi all,

I have a pivot table that has adjacent columns that work independently of the pivot table. I linked a drop down that users can select from to to control how the pivot table is filtered.

I want to Autofilter out the rows that are blank after the user selects from the drop down, but it seems like the rows that are currently hidden are based on the user's previous choice via the drop down.

Code:
sumws.Range("K13:M42").AutoFilter Field:=1, Criteria1:="<>0", Visibledropdown:=False

Do I need to declare a variable that will load which rows are blank after my user selects from the drop down, then use the auto filter? If so, what is the best way to go about doing that?

Thanks.
 

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.
As opposed to using auto filter, I looked on the internet for a For Loop instead. It seems to work better, but it seems to have a success rate of around 80%.

Code:
Dim totalRange As RangeDim cell As Range


sumws.Rows("13:42").Hidden = False




    For Each cell In ActiveSheet.Range("F13:G42")
       If cell = "" And totalRange Is Nothing Then
            Set totalRange = cell
       ElseIf cell = "" Then
            Set totalRange = Application.Union(totalRange, cell)
       End If
    Next
    
    If Not totalRange Is Nothing Then
        totalRange.EntireRow.Hidden = True
    End If
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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