我是VBA的新手,几天前刚开始学习。
我正在尝试将此索引/匹配功能转换为Excel VBA
=INDEX('[039.xls]Sales Ledger Outstanding Invoic'!$D:$D,MATCH(D2,'[039.xls]Sales Ledger Outstanding Invoic'!$E:$E,0))
这是我到目前为止所得到的:
Dim E As Long, f As Long, g As Long
Set tempWB = Workbooks.Open("C:\EDI\SLT report\039.xls", True, True).Worksheets("Sales Ledger Outstanding Invoic").Range("D2:D100")
Set dataWB = Workbooks.Open("C:\EDI\SLT report\039.xls", True, True).Worksheets("Sales Ledger Outstanding Invoic").Range("E2:E100")
E = Cells(Rows.Count, "E").End(xlUp).Row
g = 1
For f = 2 To E
If IsEmpty(Cells(f, "D")) = False Then
Cells(f, "D") = Application.WorksheetFunction.Index(tempWB, Application.WorksheetFunction.Match(A2, dataWB, 0))
g = g + 1
End If
Next f
但是这段代码给了我
下标超出范围
有人可以帮我解决吗?感谢