VBA to adjust column filter, based on dropdown selection?

DarkJester89

Board Regular
Joined
Nov 5, 2017
Messages
109
Office Version
  1. 2016
Platform
  1. Windows
Sheet 1, data with filters

Sheet 2, Dropdown with name range of filter data

Respectfully requesting how to activate filter based on dropdown, to include "All Regions", which would reset the filter to count all.

tests.png


Workbook

Had assistance with this code with a warning of " code for updating the range of the filter itself " but it keeps throwing up 1004.

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("M2")) Is Nothing Then
        Select Case Target.Value
            Case "All Regions"
                ActiveSheet.Range("$G$1:$G$134").AutoFilter Field:=1
            Case Else
                ActiveSheet.Range("$G$1:$G$134").AutoFilter Field:=1, Criteria1:=Target.Value
        End Select
    End If
End Sub

Thank you in advance.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Is col G part of a table?
If so what is it's name?
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Target, Range("M2")) Is Nothing Then
      With ActiveSheet.ListObjects("table_owssvr")
         Select Case Target.Value
            Case "All Regions"
               If .AutoFilter.FilterMode Then .AutoFilter.ShowAllData
            Case Else
            .Range.AutoFilter .ListColumns("Region").Index, Target.Value
         End Select
      End With
   End If
End Sub
 
Upvote 0
It works! If I was trying to adjust Range "M1" (moving the dropdown to another sheet), how could I could the new location if it's on another sheet?

Would a change like that force ListColumns to need an update as well? thank you so much!
 
Upvote 0
You would need to put the code in the sheet with the dropdown & replace ActiveSheet with the name of the sheet with the table.
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

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