这部分准备了一个打印列表,在代码的前面我清除所有过滤器。 在第5栏中,我有数字和数字串。数字和字母。 在输入单元格中,我只有数字。这似乎是个问题
当我输入输入单元格数字和字母时,它可以正常工作。
我的值是数字,所以我尝试将它们从字符串更改为long。 我尝试将它们格式化为文本。
我尝试过手动粘贴这些值时没问题 我可以看到VBA从单元格中获取了正确的值,它将它放在一个数组中然后没有。
Dim lr1, r, f As Long
Dim rngFilter As Range
Dim i, x
Dim a1, a2, a3, a4, a5, a6 As String
With Worksheets("a")
Set rngFilter = .ListObjects("Tabela2").Range
a1 = .Cells(2, 4).Value
a2 = .Cells(2, 5).Value
a3 = .Cells(2, 6).Value
a4 = .Cells(2, 7).Value
a5 = .Cells(2, 8).Value
a5 = .Cells(2, 9).Value
If Cells(1, 10).Value = 1 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1), Operator:=xlFilterValues
End If
If Cells(1, 10).Value = 2 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1, a2), Operator:=xlFilterValues
End If
If Cells(1, 10).Value = 3 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1, a2, a3), Operator:=xlFilterValues
End If
If Cells(1, 10).Value = 4 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1, a2, a3, a4), Operator:=xlFilterValues
End If
If Cells(1, 10).Value = 5 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1, a2, a3, a4, a5), Operator:=xlFilterValues
End If
If Cells(1, 10).Value = 6 Then
rngFilter.AutoFilter Field:=5, Criteria1:=Array(a1, a2, a3, a4, a5, a6), Operator:=xlFilterValues
End If