Peter Muller
Board Regular
- Joined
- Oct 15, 2018
- Messages
- 135
- Office Version
- 365
- Platform
- Windows
Hi All,
I am trying to write the VBA code to do the following.
I want to hide specific rows from a Filter drop down box, based on criteria in a range in a different sheet.
Criteria in Sheet 1 (Parameters), range "B2":"B12"
For each "Y", then select that criteria in sheet 2 (Budget) "B1" - filter
For each "N", then that criteria must not be selected in Budget "B1"
Excel 2016
I get the VBA coding to work when looking at two criteria to select, but it all goes wrong when on the third criteria is “Y”, but the second was “N”
This is what I have:
' NOTE
' Problem is when H6 is "N", I dont know how to not select when i get to H7
' 11 "Y" or "N" Criteria in Parameter Sheet, from H5 to H13
I am trying to write the VBA code to do the following.
I want to hide specific rows from a Filter drop down box, based on criteria in a range in a different sheet.
Criteria in Sheet 1 (Parameters), range "B2":"B12"
For each "Y", then select that criteria in sheet 2 (Budget) "B1" - filter
For each "N", then that criteria must not be selected in Budget "B1"
Excel 2016
I get the VBA coding to work when looking at two criteria to select, but it all goes wrong when on the third criteria is “Y”, but the second was “N”
This is what I have:
Code:
Sub Select_Parameters()
'
' Select_POL Macro
'
Sheets("Para").Select
If Range("H5") = "Y" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:="=General", _
Operator:=xlOr, Criteria2:="=POL"
End If
Sheets("Para").Select
If Range("H5") = "N" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:="=General"
End If
' Select_Rearing Macro
Sheets("Para").Select
If Range("H6") = "Y" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:=Array( _
"General", "POL", "REARING"), Operator:=xlFilterValues
End If
Sheets("Para").Select
If Range("H6") = "N" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:=Array( _
"General", "POL"), Operator:=xlFilterValues
End If
' Select_Laying Macro
Sheets("Para").Select
If Range("H7") = "Y" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:=Array( _
"General", "POL", "REARING", "LAYING"), Operator:=xlFilterValues
End If
Sheets("Para").Select
If Range("H7") = "N" Then
Sheets("Budget").Select
ActiveSheet.Range("$B$1:$B$2979").AutoFilter Field:=1, Criteria1:=Array( _
"General", "POL", REARING), Operator:=xlFilterValues
End If
End Sub
' NOTE
' Problem is when H6 is "N", I dont know how to not select when i get to H7
' 11 "Y" or "N" Criteria in Parameter Sheet, from H5 to H13
Last edited by a moderator: