I'm new in VBA and I created shapes that will function as buttons in my excel document that will filter/unfilter data based on color that when I click the button (for example I click "Waterproofing") it will filter data whose boxes have the color (red under "Waterproofing").
My code looks like this:
Sub Rectangle70_Click()
If ActiveSheet.FilterMode = False Then
ActiveSheet.Range("$D$4:$BA$916").AutoFilter Field:=12, Criteria1:=RGB(84, _
129, 53), Operator:=xlFilterCellColor
Else
ActiveSheet.Range("$D$4:$BA$916").AutoFilter Field:=12
End If
End Sub
My problem with above code is I have several buttons, (Example, button 1 is "Waterproofing", Button 2 is "Steel works", Button 3 is "Firefighting), and when I click "Waterproofing" (to filter) I have to click "Waterproofing" again to unfliter data before I can click "Steel works" to filter.
What I want to happen is that when I click "Waterproofing" (to filter), I can also click "Steel works" (to filter) so that data with colors under "Waterproofing" and "Steel works" will be shown. Also, I want it to be able to unfilter even though two filters are active. For example, "Waterproofing" and "Steel works" are already on filter mode, when I click "Waterproofing", it will unfilter it's column range, leaving the data under "Steel works" filtered".
Also, although it may be redundant, I created another button named "Show All" that will show all data in case the user filters under a button and forgets what buttone he/she clicked (since the code I have now limits me to clicking the same button to unfilter).
My problem with it is that when clicked accidentally and no data is filtered it creates an error that once I try to filter the data (say I clicked "Waterproofing" after I accidentally clicked "Show all") it causes all data to filter into nothing, as if hidden
Please help me on this.
My code looks like this:
Sub Rectangle70_Click()
If ActiveSheet.FilterMode = False Then
ActiveSheet.Range("$D$4:$BA$916").AutoFilter Field:=12, Criteria1:=RGB(84, _
129, 53), Operator:=xlFilterCellColor
Else
ActiveSheet.Range("$D$4:$BA$916").AutoFilter Field:=12
End If
End Sub
My problem with above code is I have several buttons, (Example, button 1 is "Waterproofing", Button 2 is "Steel works", Button 3 is "Firefighting), and when I click "Waterproofing" (to filter) I have to click "Waterproofing" again to unfliter data before I can click "Steel works" to filter.
What I want to happen is that when I click "Waterproofing" (to filter), I can also click "Steel works" (to filter) so that data with colors under "Waterproofing" and "Steel works" will be shown. Also, I want it to be able to unfilter even though two filters are active. For example, "Waterproofing" and "Steel works" are already on filter mode, when I click "Waterproofing", it will unfilter it's column range, leaving the data under "Steel works" filtered".
Also, although it may be redundant, I created another button named "Show All" that will show all data in case the user filters under a button and forgets what buttone he/she clicked (since the code I have now limits me to clicking the same button to unfilter).
My problem with it is that when clicked accidentally and no data is filtered it creates an error that once I try to filter the data (say I clicked "Waterproofing" after I accidentally clicked "Show all") it causes all data to filter into nothing, as if hidden
Please help me on this.