1. 在excel vba編程中使用vlookup()時(shí),vlookup不能直接寫(xiě)成excel公式中的樣式[ =VLOOKUP(123,A1:C100,3,FALSE) ],會(huì )出現“子過(guò)程或函數未定義”的錯誤,應該寫(xiě)成application.VLOOKUP(123,A1:C100,3,FALSE) 或者寫(xiě)成 Application.WorksheetFunction.VLookup()方式。
2. 如果使用Application.WorksheetFunction.VLookup()時(shí),會(huì )報錯“不能取得worksheetfunction的vlookup屬性”,因此最好使用第一種形式:application.VLOOKUP(123,A1:C100,3,FALSE) 。具體原因根據這里所說(shuō),Application.WorksheetFunction.VLookup()會(huì )進(jìn)入debug模式,application.VLOOKUP(123,A1:C100,3,FALSE)不會(huì )進(jìn)入debug模式。當然,如果想忽略錯誤可以直接寫(xiě) "On Error Resume Next" 。
3.在使用上面任何一種形式的時(shí)候都有可能出現找不到“123”的情況,這種情況可以通過(guò)判斷語(yǔ)句 Application.WorksheetFunction.IsError() 和 if 配合來(lái)處理,讓錯誤輸出成自己想要的格式。
- findvalue = Application.VLookup(ActiveWorkbook.Worksheets(1).Range("E" & i), o, 2, 0) ' o為所查找的區域
- If (Application.WorksheetFunction.IsError(findvalue)) Then
- ActiveWorkbook.Sheets(1).Cells(i, "G").Value = ActiveWorkbook.Sheets(1).Cells(i, "E").Value
- 'vlookup找不到,則G列的值等于E列的值
- Else
- ActiveWorkbook.Sheets(1).Cells(i, "G").Value = findvalue
- End If
http://iofai.com/559.html
http://www.exceltip.net/thread-20656-1-1.html
http://www.excelpx.com/forum.php?mod=viewthread&tid=284178
http://wubinsq.blog.163.com/blog/static/50751341200822144057698/
http://blog.csdn.net/iamlaosong/article/details/8929404
http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx
http://www.mrexcel.com/forum/excel-questions/584913-application-vs-application-worksheetfunction.html
聯(lián)系客服