我試圖使用VLOOKUP來檢查我的變量是否出現在listobject中,如果是這樣,則檢索相應的值。在VLOOKUP中使用變量
我的代碼總是轉到在以下行雖然錯誤:
shtData.Cells(rowNumber, perf1).Value = wsFunc.IfError(wsFunc1.VLookup(shtData.Cells(rowNumber, cep1).Value, perfTable, 2, False), Null)
我的代碼如下:
Dim wb As Workbook
Set wb = ActiveWorkbook
Dim wsFunc As WorksheetFunction
Set wsFunc = Application.WorksheetFunction
Dim wsFunc1 As WorksheetFunction
Set wsFunc1 = Application.WorksheetFunction
Dim cep As Variant
Dim perfTable As ListObject
Set perfTable = perfData.ListObjects("PerfTable")
Dim cepTable As ListObject
Set cepTable = perfData.ListObjects("cepTable")
perfCol = perfTable.ListColumns("Column1").Index
perfSort = perfTable.ListColumns("Column2").Index
cepCol = cepTable.ListColumns("Column1").Index
cepSort = cepTable.ListColumns("Column2").Index
On Error GoTo errHandler
Set usedRange = returnUsedRange(shtData, wb)
Set perfRange = returnUsedRange(perfData, wb)
Set cepRange = returnUsedRange(perfData, wb)
For Each Row In usedRange
For Each sec In secRange
rowNumber = Row.Row
secRow = sec.Row
shtData.Cells(rowNumber, perf1).Value = wsFunc.IfError(wsFunc1.VLookup(shtData.Cells(rowNumber, cep1).Value, perfTable, 2, False), Null)
Next
我不認爲你可以像這樣返回null。你可能不得不返回'''''或'0'。這可能有助於包括錯誤所說的內容。 – Bigtree
我試過將它改爲「」相同的結果 – db579