I’ve got a spreadsheet in my Excel 2010 workbork with a lot of data. This page can be sorted by the build in autofilter.
On another sheet I have made a button which does some of the sorting.
For example:
Sub forsteKvartalAftaleIndgaet()
'
Sheets("AMRM01").Select
ActiveSheet.Range("$A$12:$P$76").AutoFilter Field:=2, Criteria1:="<01-04", _
Operator:=xlAnd
Sheets("Ark2").Select
End Sub
Sub andenKvartalAftaleIndgaet()
'
Sheets("AMRM01").Select
ActiveSheet.Range("$A$12:$P$76").AutoFilter Field:=2, Criteria1:=">01-04", _
Operator:=xlAnd, Criteria2:="<01-07"
Sheets("Ark2").Select
End Sub
When I do this the sheet shows the first and second quarter of the year. I’ve got two buttons which show the third quarter and fourth quarter of the year which looks like this:
Sub TredjeKvartalAftaleIndgaet()
'
Sheets("AMRM01").Select
ActiveSheet.Range("$A$12:$P$76").AutoFilter Field:=2, Criteria1:=">01-07", _
Operator:=xlAnd, Criteria2:="<01-10"
Sheets("Ark2").Select
End Sub
Sub FjerdeKvartalAftaleIndgaet()
'
Sheets("AMRM01").Select
ActiveSheet.Range("$A$12:$P$76").AutoFilter Field:=2, Criteria1:=">01-10", _
Operator:=xlAnd, Criteria2:="<31-12"
Sheets("Ark2").Select
End Sub
My problem: When I press the button (Second quarter) it filters and shows the second quarter. But when I press the “Third Quarter” button it removes the Second Quarter filter and shows the Third Quarter.
Is it possible to write some kind of VBA code which makes it possible to have both buttons pressed at the same time, like it’s possible to do with the build in autofilter buttons?
If you’re not quite sure what I mean, please ask for a better explanation.
Thanks in advance
Something like this perhaps? So it stands true for both ways? i.e.if
1) You select 2nd quarter first then it will show 2nd quarter and then when you press 3rd quarter, it will show you 2nd and 3rd quarter.
2) You select 3rd quarter first then it will show 3rd quarter and then when you press 2nd quarter, it will show you 2nd and 3rd quarter.
Note: I have not tested the code so let me know if you get any errors 🙂