AutoFilter Yes / No based on numerical value

nicespreadsheetmate

New Member
Joined
Dec 21, 2021
Messages
2
Office Version
  1. 365
  2. 2021
Hi! Some fantastic info on these forums, thanks all. Unfortunately I wasn't able to find a response to this specific issue in my macro.

I'm creating a spreadsheet for work that is populated with all of our projects and their embodied carbon rankings. The user will be able to search and filter the data based on drop down strings. This is all fine. Unfortunately, one of filters will be - if the user selects Basement = yes, filter all the data where the data in the "Below Ground" column > 0. Basically it works on the assumption that if the below ground value is greater than 0 then the building has a basement.

VBA Code:
sht.Range("A2:T2").AutoFilter field:=14, Criteria1:="=*" & sht2.Range("Dashboard!$C2").Value & "*"
sht.Range("A2:T2").AutoFilter field:=13, Criteria1:="=*" & sht2.Range("Dashboard!$C3").Value & "*"
sht.Range("A2:T2").AutoFilter field:=20, Criteria1:="=*" & sht2.Range("Dashboard!$C4").Value & "*"

C4 in the above is the Yes or No drop down option, Field 20 is a numeric value either 0 or greater than 0.

Thanks kindly,

Rob
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
See if this does what you need:-

VBA Code:
    sht.Range("A2:T2").AutoFilter field:=14, Criteria1:="=*" & sht2.Range("Dashboard!$C2").Value & "*"
    sht.Range("A2:T2").AutoFilter field:=13, Criteria1:="=*" & sht2.Range("Dashboard!$C3").Value & "*"
    
    ' Has Basement Y/N
    Select Case UCase(sht2.Range("Dashboard!$C4").Value)
        Case "YES"
            sht.Range("A2:T2").AutoFilter field:=20, Criteria1:=">0"
        Case "NO"
            sht.Range("A2:T2").AutoFilter field:=20, Criteria1:="=0"
        Case Else
            sht.Range("A2:T2").AutoFilter field:=20
    End Select
 
Upvote 0
Solution
See if this does what you need:-

VBA Code:
    sht.Range("A2:T2").AutoFilter field:=14, Criteria1:="=*" & sht2.Range("Dashboard!$C2").Value & "*"
    sht.Range("A2:T2").AutoFilter field:=13, Criteria1:="=*" & sht2.Range("Dashboard!$C3").Value & "*"
   
    ' Has Basement Y/N
    Select Case UCase(sht2.Range("Dashboard!$C4").Value)
        Case "YES"
            sht.Range("A2:T2").AutoFilter field:=20, Criteria1:=">0"
        Case "NO"
            sht.Range("A2:T2").AutoFilter field:=20, Criteria1:="=0"
        Case Else
            sht.Range("A2:T2").AutoFilter field:=20
    End Select
Works a treat, thank you for taking the time.

Best,
Rob
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,208
Members
448,874
Latest member
b1step2far

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