2014-09-03 48 views
1

我在下面的語句中得到了一個語法錯誤,它包含了If,IsError和VLOOKUP語句 - 我一直在嘗試一切.....任何人都知道爲什麼?If,IsError,VLOOKUP語法錯誤 - 任何人都知道爲什麼?

If Application.Worksheetfunction.IsError(VLOOKUP(cell.Value,'[Codes.xlsx]Processing Codes'!ProcessingCodesTable,5,FALSE)) = FALSE then 

感謝任何幫助將不勝感激!

回答

0

VLOOKUP is not一個VBA函數。

上一個問題「Writing a VLOOKUP function in vba」提供了多種解決方法。看起來你可以用Application.WorksheetFunction.VLookup代替VLOOKUP

+0

謝謝,我已經改正了這一點,但我相信也有我的表數組語法錯誤,因爲如果我是一個靜態的範圍等來代替它作爲「A1:A15」,錯誤消失。 – user3242388 2014-09-03 18:17:29

+0

@ user3242388無論ProcessingCodesTable的範圍是什麼,您都要求返回該範圍內的第5列 – datatoo 2014-09-03 18:40:06

+0

是不是您的'[Codes.xlsx]處理代碼'ProcessingCodesTable是一個已命名的範圍而不是VBA變量,因此需要處於雙引號呢? – Captain 2014-09-03 18:41:23

0

你也許能夠適應這樣的事情

Sub lookupPC() 
On Error GoTo ErrHandler 
Dim result As Variant 
Dim ws As Worksheet 
Set ws = ActiveWorkbook.Sheets("Processing Codes") 
For Each cell In Range("a1:a100") 
    If IsError(Application.WorksheetFunction.VLookup(cell.Value, ws.Range("ProcessingCodesTable"), 5, False)) = False Then 
    result = Application.WorksheetFunction.VLookup(cell.Value, ws.Range("ProcessingCodesTable"), 5, False) 
    End If 
MsgBox (result) 
Next cell 
ErrHandler: 
MsgBox (cell.Address & " value not available in table") 
End Sub 
+0

實際上,如果沒有有效的查找值,則可能應該忽略IsError函數,並自己處理錯誤 – datatoo 2014-09-04 15:19:52

相關問題