Filter range based on list if cell Drop Down is AM

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
Hello I have a really difficult Filter request

My range to be Filtered is A3:Q500

C1 is Data Validated with List AM, PM, BOTH. (Users Will selected one)

If C1="AM" I would like the Range be filtered to show only AM TIMES.

The AM TIMES and PM TIMES are in NumberLetter Format The Filtered range are also in this format. I have a List of All the possible AM Times in Range AA3:AA42 and PM TIMES in AB3:AB42. The filtered range might not consist of all the possible variation but will have most.

in other words If C1="AM" to Filter based on list in Range AA3:AA42. If C1="PM" to Filter based on list in Range AB3:AB42, if C1="BOTH" show all data

the Filter column would be column 5
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Thanks for the quick reply. I was looking for more of a VBA approach
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Ary As Variant
   
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "C1" Then
      If Target.Value = "BOTH" Then
         Me.Range("A3:Q3").AutoFilter
         Exit Sub
      ElseIf Target.Value = "AM" Then
         Ary = Application.Transpose(Range("AA3:AA42").Value)
      ElseIf Target.Value = "PM" Then
         Ary = Application.Transpose(Range("AB3:AB42").Value)
      End If
      Me.Range("A3:Q3").AutoFilter 5, Ary, xlFilterValues
   End If
End Sub
 
Upvote 0
Thanks Fluff for the code. If the sheet is protected and I need the above code to run. where or how I would go about inputting this

VBA Code:
Me.Unprotect Password:="Password"

I have times to place this in the code but it does not seem to unprotect sheet before the code is ran.
 
Upvote 0
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Ary As Variant

   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "C1" Then
      Me.Unprotect "Password"
      If Target.Value = "BOTH" Then
         Me.Range("A3:Q3").AutoFilter
         Me.Protect "Password"
         Exit Sub
      ElseIf Target.Value = "AM" Then
         Ary = Application.Transpose(Range("AA3:AA42").Value)
      ElseIf Target.Value = "PM" Then
         Ary = Application.Transpose(Range("AB3:AB42").Value)
      End If
      Me.Range("A3:Q3").AutoFilter 5, Ary, xlFilterValues
      Me.Protect "Password"
   End If
End Sub
 
Upvote 0
I still get the protected sheet error not sure why
 
Upvote 0
What is the exact error & when do you get it?
 
Upvote 0
Error "The Cell or Chart you're trying to change is on a protected sheet. to make a change, unprotect sheet. You might be requested to enter a password.

it occurs when I try to change C1 Value
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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