Filter Table Based on cell value

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi Folks

I have this bit of code that i set up ages ago to filter 3 columns in my table based on cell values in B2, B3, B4.
It works perfectly. I have been trying to add another one to B5 to filter field 9 which should be as simple as
copying and pasting then changing the values, however it does not work.

I can ammend one of the origonal 3 and it works but if i add another one to the code it doesnt.

I dont ever remember having to do anything special to cells B2,B3 and B4.

I have been at this for 2 days now trying to figure this out. Tried different sheets, checking cells are not locked......This is driving me nuts.....!

VBA Code:
If target.Address = "$B$2" Then
If Range("B2") = "All Categories" Then
ActiveSheet.Range("table5").AutoFilter Field:=6
Else
Range("table5").AutoFilter Field:=6, Criteria1:=Range("B2")
End If
End If


If target.Address = "$B$3" Then
If Range("B3") = "All Areas" Then
ActiveSheet.Range("table5").AutoFilter Field:=2
Else
Range("table5").AutoFilter Field:=2, Criteria1:=Range("B3")
End If
End If


If target.Address = "$B$4" Then
If Range("B4") = "All Status" Then
ActiveSheet.Range("table5").AutoFilter Field:=40
Else
Range("table5").AutoFilter Field:=40, Criteria1:=Range("B4")
End If
End If
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I DID IT!!!

Did not know that when referencing the cell address/range in the code that it needs to be in capitals. Tried it and it now works perfectly.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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