samedi 10 février 2018

VBA. If multiple checkbox are checked then filter array by multiple month

Hi I looking for simpler way to do this.

Now i got 3 checkboxes Jan, Feb and Mar. I only made januar code so far but my goal is all 12 months. Is there a better way to do this? Because if need to if check all 12 times 12 outcomes

Please help - Please ask any questions :)

/Tobias

Private Sub CheckBox_jan_Click()
    If CheckBox_jan.Value = True And CheckBox_feb.Value = True And CheckBox_mar.Value = True Then
    Sheets("beregninger").Select
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2 'clears filter
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2, Operator:= _
        xlFilterValues, Criteria2:=Array(1, "1/31/2007", 1, "2/28/2007", 1, "3/31/2007")

    ElseIf CheckBox_jan.Value = True And CheckBox_mar.Value = True Then
        Sheets("varmekilde kW").Select
    Sheets("beregninger").Select
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2 'clears filter
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2, Operator:= _
        xlFilterValues, Criteria2:=Array(1, "1/31/2007", 1, "3/31/2007")
        Sheets("varmekilde kW").Select

    ElseIf CheckBox_jan.Value = True And CheckBox_feb.Value = True Then
        Sheets("varmekilde kW").Select
    Sheets("beregninger").Select
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2 'clears filter
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2, Operator:= _
        xlFilterValues, Criteria2:=Array(1, "1/31/2007", 1, "2/28/2007")
        Sheets("varmekilde kW").Select

    ElseIf CheckBox_jan.Value = True Then
    Sheets("beregninger").Select
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2 'clears filter
    ActiveSheet.Range("$A$2:$AJ$8762").AutoFilter Field:=2, Operator:= _
        xlFilterValues, Criteria2:=Array(1, "1/31/2007")
        Sheets("varmekilde kW").Select
    End If
End Sub

Private Sub CheckBox_feb_Click()

End Sub

Private Sub CheckBox_mar_Click()

End Sub




Aucun commentaire:

Enregistrer un commentaire