Apply boolean autofiltration criteria to another language

I have a table that I filter based on a boolean value.

Whenever a value TRUE, I want it to be shown.

I use autofilter and the following working VBA code:

lCol = tbl.ListColumns("xFilter").Index
With tbl
    If .AutoFilter.FilterMode Then .AutoFilter.ShowAllData
    .Range.AutoFilter Field:=lCol, Criteria1:="TRUE"
End With

I am working on an English copy of Excel. When I try to do this on an instance in Dutch, I need to manually set the criterion WAAR(Dutch equivalent TRUE).

I can add several criteria and specify:

Criteria1:="WAAR", Operator:=xlOr, Criteria2:="TRUE"

However, if I then went to Germany and Spain, I would have to write:

Criteria1:="WAAR", Operator:=xlOr, Criteria2:="TRUE", Operator:=xlOr, Criteria3:="WAHR", Operator:=xlOr, Criteria4:="VERDADERO"

Is there a way to make it Criteria1:="TRUE"work in any language?

+4
2

CBool, TRUE AutoFilter.

CBool(1) "" .

Option Explicit

Sub TestLanguageIndependentBooleanForAutoFilter()

    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim lCol As Long

    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set tbl = ws.ListObjects(1)

    lCol = tbl.ListColumns("xFilter").Index
    With tbl
        If .AutoFilter.FilterMode Then .AutoFilter.ShowAllData
        .Range.AutoFilter Field:=lCol, Criteria1:=CBool(1)
    End With

End Sub

:

enter image description here

+2

:

1: = (True)

0

Source: https://habr.com/ru/post/1677231/


All Articles