I have designed an userform with 7checkboxes. Each Checkbox has an call function, which is called as autofilter. This function autofilter, helps to filter the field 4 in my sheet and Displays the result.
Here, I have 3 cases.
Case1. when Checkbox1 is selected, Display the result of autofilter1.
case2: when checkboxes1 and 2 are selected, Display the result of autofilter1 and 2.
Note: it is not necessary that user can select just checkboxes 1 and 2, it can be checkbox 2 and 3 or 1 and 3 as well or sometime all 3 selection.
Case3: when nothing is selected, clear the filter.
I am successful in generating the case1 Situation, How should I proceed, in order to achieve case2 and case3.
Below is the autofilter function, which is assigned to checkbox1.
Sub autofilter1()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Result")
wslr = ws.Cells(Rows.Count, 1).End(xlUp).Row
Set myfilt = ws.Range("A1:D" & wslr)
myfilt.autofilter Field:=4, Criteria1:= _
"USA"
End Sub
autofilter function assigned to checkbox2.
Sub autofilter2()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Result")
wslr = ws.Cells(Rows.Count, 1).End(xlUp).Row
Set myfilt = ws.Range("A1:D" & wslr)
myfilt.autofilter Field:=4, Criteria1:= _
"Germany"
End Sub
autofilter function assigned to Checkbox 3.
Sub autofilter3()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Result_APQP")
wslr = ws.Cells(Rows.Count, 1).End(xlUp).Row
Set myfilt = ws.Range("A1:D" & wslr)
myfilt.autofilter Field:=4, Criteria1:= _
"France"
End Sub
In the Command Button, "Go", I have the following code,
Private Sub CommandButton4_Click()
If CheckBox1.Value = True Then
Call autofilter1
End If
If CheckBox2.Value = True Then
Call autofilter2
End If
If CheckBox3.Value = True Then
Call autofiletr3
End If
End Sub
I have attached the Image also, for reference. In the Image, i have just taken the example for 3 Checkbox.