1
私は小さなプログラムを作っています。メインシートには、2つのコンボボックスがあります。複数の条件を使用して値をフィルタリングするコード
各コンボボックスから値を選択すると、データがフィルタリングされます。しかし、私は小さな問題に直面しています。私は、両方のコンボボックスにALL値が必要です。その値を選択すると、その列をフィルタリングすべきではありません。これまでのところ、私のコードは次のようである
:ComboBox1のは長さゼロの文字列である場合
Sub submit()
Dim ws As Worksheet, tbl As ListObject, rng As Range
Set ws = Sheets("Graphical Summary")
Set tbl = ws.ListObjects("Table5")
Set rng = tbl.DataBodyRange
With tbl
.Range.AutoFilter Field:=1
.Range.AutoFilter Field:=3
End With
With rng
If Sheets("Graphical Summary").ComboBox1.Value = "All" Then .AutoFilter Field:=2, Criteria1:=Sheets("Graphical Summary").ComboBox2.Value
If Sheets("Graphical Summary").ComboBox1.Value <> vbNullString Then .AutoFilter Field:=1, Criteria1:=Sheets("Graphical Summary").ComboBox1.Value
If Sheets("Graphical Summary").ComboBox2.Value <> vbNullString Then .AutoFilter Field:=2, Criteria1:=Sheets("Graphical Summary").ComboBox2.Value
End With
End Sub