"데이터베이스"(DB_SHEET)에서 일부 세금을 찾으려면 Vlookup을 사용하려고합니다. 내 이름이 내 DB에 존재하지 않으면 VlookUp에서 '1004'오류가 발생합니다.캐치 Vlookup 1004 오류
왜 'On Error GoTo Err1'이 오류를 잡아 내지 못합니까?
내 코드 :
Dim tax1 as Double, tax2 as Double, name as String
On Error GoTo Err1
While Cells(rowIndex, 1) <> ""
name = Cells(rowIndex, 4)
fin = Cells(rowIndex, 5) * Cells(rowIndex, 6)
tax1 = WorksheetFunction.VLookup(name, Sheets(DB_SHEET).Range("D:G"), 3, False)
tax2 = WorksheetFunction.VLookup(name, Sheets(DB_SHEET).Range("K:P"), 2, False)
Cells(rowIndex, 8) = (fin * tax1) - (fin * tax2)
Err1:
rowIndex = rowIndex + 1
Wend
On Error Goto 0
이미 작동하는 코드를 알고 있지만 나는 "오류에" "WorksheetFunction"를 캐치 오류 사용을 할 수없는 이유를 이해하고자합니다. 작동
다른 버전 :
Dim tax1 as Variant, tax2 as Variant, name as String
While Cells(rowIndex, 1) <> ""
name = Cells(rowIndex, 4)
fin = Cells(rowIndex, 5) * Cells(rowIndex, 6)
tax1 = WorksheetFunction.VLookup(name, Sheets(DB_SHEET).Range("D:G"), 3, False)
tax2 = WorksheetFunction.VLookup(name, Sheets(DB_SHEET).Range("K:P"), 2, False)
If Not IsError(tax1) And not IsError(tax2) Then
Cells(rowIndex, 8) = (fin * tax1) - (fin * tax2)
End if
rowIndex = rowIndex + 1
Wend
편집 (후 : K_B 답)
1) WorksheetFunction.Vlookup의 내가 Application.Vlookup를 사용하는 경우 (...) INSEAD (.. .) 나는 "Error 13"을 얻었다.
그런 루프에서 오류 처리기를 사용할 수 있다고 생각지 않습니다. 루프 외부로 이동 한 다음 행 번호를 증가시킨 후 다시 시작을 추가하십시오. –
예. 할 수 있습니다. 그리고 "Resume Next"를 사용하고 싶지 않습니다.이 코드에서 "On erro goto Label :"을 사용하는 것을 선호합니다. – Makah
Resume Next는 오류 라벨 다음에 나옵니다. "On Error Resume Next"사용을 제안하지 않았습니다. –