我构建了一个数据透视表,为我提供了一些产品代码和其他信息,我需要按照产品代码查看
我要做的是在给定范围内输入约20个产品代码。运行VBA宏,然后筛选A1以获取我在Range中输入的值。 我有一个可用的代码,但它无法正常工作。
我收到错误类型不匹配
Sub ArrayAutofilterFromNamedRange()
Dim oWS As Worksheet
Dim oRange As Range
Dim numrows As Integer
Dim i As Integer
Dim arCriteria(0 To 100) As String
On Error GoTo Err_Filter
Set oWS = ActiveSheet
Set oRange = ActiveWorkbook.ActiveSheet.Range("mydynamicrange")
numrows = oRange.Rows.Count
i = 0
For Each Row In oRange
arCriteria(i) = Row.Value
i = i + 1
Debug.Print arCriteria(i)
Next Row
oWS.Range("A1").AutoFilter Field:=1, Criteria1:=arCriteria,
Operator:=xlFilterValues
Finish:
If Not oWS Is Nothing Then Set oWS = Nothing
Err_Filter:
If Err <> 0 Then
MsgBox Err.Description
Err.Clear
GoTo Finish
End If
End Sub
答案 0 :(得分:1)
您的代码行:
oange
将失败,因为尚未定义{{1}}。
(可能还有其他问题)