jeudi 15 février 2018

VBA Filter using checkboxes in Excel?

I'm new to VBA in Excel and trying to build a menu that will allow users to enter filter criteria using checkboxes. In this case, filter by states. Everything works fine when there is only one state selected, but multiple states clears the filter. The code I'm using to build the filter criteria string is below. I've tried adding additional quotes ("AL", "AK") but that clears the filter when only a single state is selected. Any suggestions would be greatly appreciated.

If Sheets("Menu").ckAL.Value = True Then
    strCriteria = strCriteria & ", AL"

End If

If Sheets("Menu").ckAK.Value = True Then
    strCriteria = strCriteria & ", AK"

End If

strCriteria = Mid(strCriteria, 2)

ActiveSheet.Range("$A$4:$AR$16998").AutoFilter Field:=3, Criteria1:=Array(strCriteria), Operator:=xlFilterValues

Thanks.

Bruce




Aucun commentaire:

Enregistrer un commentaire