mercredi 24 juin 2015

Filter Options Using Checkboxes in an Excel VBA Userform

3I'm working on a userform that allows the end user to filter first by individual business units, then select the "flags" (0, 1, 2) they want to see. The combobox that lists the various business units works fine, it's the "flags" I'm having an issue with.

The users need to be able to select more than one flag to analyze. I orignally thought that using Checkboxes would be the way to go, however I can't seem to get the code to perform as I expect it to. If one checkbox is selected, it works fine, but if more than one is selected, it only filters by the value of the first checkbox selected.

Private Sub CommandButton1_Click()
   Application.ScreenUpdating = False

ActiveWorkbook.Sheets("Masterlist").Activate
    Range("I1").Select
    ActiveSheet.Range("I1").AutoFilter Field:=9, Criteria1:=ComboBox1

With ActiveSheet
    If CheckBox1.Value = True Then
      ActiveSheet.Range("BL1").AutoFilter Field:=64, Criteria1:="0"
    ElseIf CheckBox2.Value = True Then
     ActiveSheet.Range("BL1").AutoFilter Field:=64, Criteria1:="1"
    ElseIf CheckBox3.Value = True Then
     ActiveSheet.Range("BL1").AutoFilter Field:=64, Criteria1:="2"
    End If
End With

Application.ScreenUpdating = True
End Sub

Is there a better choice? Or can the code I already have be modified to work?




Aucun commentaire:

Enregistrer un commentaire