我想在一個簡單的VBA函數使用VLOOKUP,但它不斷地返回#VALUE!
下面是代碼:
Public Function getAreaName(UBR As Integer) As String
Dim result As String
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("UBR Report")
' check level 3 then 2 then 4 then 5
result = Application.WorksheetFunction.VLookup(UBR, sheet.Range("UBRLookup"), Application.WorksheetFunction.Column(sheet.Range("UBRLookup[Level 3]")), False)
getAreaName = result
End Function
有什麼想法?
我使用excel 2007 tablename [column]語法和column()函數來自動確定偏移量。不過,我會嘗試使用手動設置。 – jwoolard 2009-08-21 15:13:22
更新了上述內容。 Debug.Print註釋是否在您的Excel 2007版本上運行? – Andy 2009-08-25 08:51:55