I'm using Excel 2013 and I have a spreadsheet where the Filter setting is on. I am working on code that will uncheck an item in column B's filter if a certain value like, "Cat", is in column C. In the case below, it should just leave the Tree and Bark rows.
<tbody>
</tbody>
QUESTION:
I just want to see if someone can tell me if Excel is able to do this using Excel VBA? And if someone can start me on the path on how to go about it.
I don't see anything on the internet about this. I may be phrasing my search incorrectly in Google, but I've tried different ways today.
I'VE TRIED:
1. I have a For/Next loop, etc., with If/Then inside that but the line of code I'm concerned about to filter is:
where 'matchedaddress' is the variable where I've stored "Cat".
Problem: But this will uncheck everything in column B I think b/c it's not offsetting to filter column B based on column C.
2. So I tried using Offset within the AutoFilter parameters. I get an error but I need it to do this.
Problem: But I get 'Run Time Error 450: Wrong number of arguments or invalid property assignment', which is probably b/c of the Offset within the Field parameter.
Thank you for your help.
Fruit | Filter | Animal |
Apples | 14756 | Cat |
Oranges | 20000 | Cat |
Tree | 14756 | Dog |
Bark | 78944 | Bird |
<tbody>
</tbody>
QUESTION:
I just want to see if someone can tell me if Excel is able to do this using Excel VBA? And if someone can start me on the path on how to go about it.
I don't see anything on the internet about this. I may be phrasing my search incorrectly in Google, but I've tried different ways today.
I'VE TRIED:
1. I have a For/Next loop, etc., with If/Then inside that but the line of code I'm concerned about to filter is:
Code:
ActiveSheet.Range(Cells(iBilling, "B"), Cells(iBilling, lastcolBilling)).AutoFilter Field:=2, Criteria1:=matchedaddress, Operator:=xlAnd
where 'matchedaddress' is the variable where I've stored "Cat".
Problem: But this will uncheck everything in column B I think b/c it's not offsetting to filter column B based on column C.
2. So I tried using Offset within the AutoFilter parameters. I get an error but I need it to do this.
Problem: But I get 'Run Time Error 450: Wrong number of arguments or invalid property assignment', which is probably b/c of the Offset within the Field parameter.
Code:
ActiveSheet.Cells(iBilling, "C").AutoFilter Field:=ActiveSheet.Range.Offset(0, -1), Criteria1:=matchedaddress, Operator:=xlAnd
Thank you for your help.
Last edited: