嘿,我的脚本字典出现了问题。它应该过滤掉它所做的给定文本,但是它也要过滤我想要显示的列中的数值(0,1,2)。
任何帮助将不胜感激!
'Filter Prefixes
Set arr = CreateObject("scripting.dictionary")
With ActiveSheet
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
Select Case UCase(.Cells(i, "C").Value2)
Case "NA", "ND", "NH", "NK", "NL", "NQ", "NV"
'do nothing
Case Else
arr.Item(.Cells(i, "C").Value2) = vbNullString
End Select
Next i
.Range("A1:CU" & lr).AutoFilter Field:=3, Criteria1:=arr.keys,
Operator:=xlFilterValues
End With
答案 0 :(得分:3)
只需添加一个测试以查看该值是否为数值,然后再将其添加到过滤器字典中即可:
Select Case UCase(.Cells(i, "C").Value2)
Case "NA", "ND", "NH", "NK", "NL", "NQ", "NV"
'do nothing
Case Else
If Not IsNumeric(.Cells(i, "C").Value2) Then
arr.Item(.Cells(i, "C").Value2) = vbNullString
End If
End Select
答案 1 :(得分:2)
我相信这是您想要的:
arr.Item(CStr(.Cells(i, "C").Value2))