ExcelVBA 指定列にオートフィルタON

.AutoFilter すると ON/OFF トグルするので、指定行にオートフィルタ適用されてるか確認して処理してます。

' オートフィルタの範囲の最初の行がRowNum行目か確認
Function IsAutoFilterOnRow(WorkBookName, SheetName, RowNum) As Boolean
    Dim ws As Worksheet
    Set ws = Workbooks(WorkBookName).Sheets(SheetName)  ' シート名を必要に応じて変更
    
    ' オートフィルタが設定されているか確認
    If ws.AutoFilter Is Nothing Then
        IsAutoFilterOnRow = False
    Else
        ' オートフィルタの範囲の最初の行がRowNum行目か確認
        If ws.AutoFilter.Range.Row = RowNum Then
            IsAutoFilterOnRow = True
        Else
            IsAutoFilterOnRow = False
        End If
    End If
End Function

' 指定行にオートフィルタ設定
Sub SetAutoFilterForRow(WorkBookName, SheetName, RowNum, bEnable)

    Dim ws As Worksheet
    Set ws = Workbooks(WorkBookName).Sheets(SheetName)

    If bEnable = True Then
        If IsAutoFilterOnRow(WorkBookName, SheetName, RowNum) = True Then
            'pass
        Else
            ws.Rows(RowNum).AutoFilter
        End If
    Else
        If IsAutoFilterOnRow(WorkBookName, SheetName, RowNum) = True Then
            ws.Rows(RowNum).AutoFilter
        Else
            'pass
        End If
    End If

End Sub