jeudi 27 mai 2021

Vba autofilter problem on all sheets (with checkboxs and in one column)

I would like to adapt this code so that it works on all the worksheets of my excel. For the moment it only marks on the active sheet.

Thank you very much in advance, an answer would save me the day.

Benten667

PS: I am looking for the answer from several experts. Same question right here: link

Dim filterValues()
Dim counter As Long
Dim ct As MSForms.Control

For Each ct In Me.Controls
    If TypeName(ct) = "CheckBox" Then
        If ct.Value = True Then
            ReDim Preserve filterValues(counter)
            filterValues(counter) = ct.Caption
            counter = counter + 1
        End If
    End If
Next ct
If counter > 0 Then
    With ActiveSheet
        .AutoFilterMode = False
        With .Range("G1", .Cells(.Rows.Count, "G").End(xlUp))
        .AutoFilter
        .AutoFilter field:=1, Criteria1:=filterValues, Operator:=xlFilterValues
        End With
    End With
End If



Aucun commentaire:

Enregistrer un commentaire