我有这个文件,它根据来自另一个页面的值进行过滤。我的问题是如果列表列中没有值,是否可以忽略字段?
现在,如果未填写所有列表值,则会发生错误。列表值是照片中的 Criteria_C 等。
谢谢
另外,我如何让它显示多个结果?
Sub Proto()
Dim cList As Variant
Dim ccList As Variant
Dim uList As Variant
Dim towList As Variant
Dim aList As Variant
Dim pmList As Variant
Dim wsP As Worksheet
Dim wsL As Worksheet
Dim rng_C As Range
Dim rng_CC As Range
Dim rng_U As Range
Dim rng_ToW As Range
Dim rng_A As Range
Dim rng_PM As Range
Dim rng_Projects As Range
Set wsP = Worksheets("Projects")
Set wsL = Worksheets("Lists")
Set rng_Projects = wsP.Range("$B$6").CurrentRegion
Set rng_C = wsL.Range("List_C")
Set rng_CC = wsL.Range("List_CC")
Set rng_U = wsL.Range("List_U")
Set rng_ToW = wsL.Range("List_ToW")
Set rng_A = wsL.Range("List_A")
Set rng_PM = wsL.Range("List_PM")
cList = rng_C.Value
ccList = rng_CC.Value
uList = rng_U.Value
towList = rng_ToW.Value
aList = rng_A.Value
pmList = rng_PM.Value
rng_Projects.AutoFilter Field:=2, Criteria1:=Application.Transpose(cList)
rng_Projects.AutoFilter Field:=3, Criteria1:=Application.Transpose(ccList)
rng_Projects.AutoFilter Field:=4, Criteria1:=Application.Transpose(uList)
rng_Projects.AutoFilter Field:=5, Criteria1:=Application.Transpose(towList)
rng_Projects.AutoFilter Field:=7, Criteria1:=Application.Transpose(aList)
rng_Projects.AutoFilter Field:=8, Criteria1:=Application.Transpose(pmList), Operator _
:=xlFilterValues
End Sub