我無法弄清楚如何處理在我的宏中引發的錯誤。通過application.Vlookup
我搜索一個值。問題是,如果該值不存在宏停止。excel vba處理出錯
我試過On Error Resume Next
這工作正常,但我想告訴用戶該值不存在。
Private Sub CommandButton1_Click()
Dim Num As Double
Dim Cle As Integer
Dim Dpt As String
Dim Age As Integer
Dim Essaidate As String
Dim CommNaiss As String
Dim NumOrdre As String
Dim Reg As String
'Initialisons la date du jour
CeJour = Date
Num = TextBox1.Text
Cle = 97 - (Num - (Int(Num/97) * 97))
If Cle < 10 Then
Label2.Caption = "0" & Cle
Else
Label2.Caption = Cle
End If
If Mid(TextBox1.Text, 1, 1) = "1" Then
Label4.Caption = "Masculin"
Else
Label4.Caption = "Féminin"
End If
Essaidate = "1" & "/" & Mid(TextBox1, 4, 2) & "/" & "19" & Mid(TextBox1, 2, 2)
'MsgBox ("La date de naissance (sans le jour) de cette personne est :" & Essaidate)
Dpt = Application.VLookup(Mid(TextBox1.Text, 6, 2), Range("M1:N96"), 2, False)
Label6.Caption = Dpt & " (" & Mid(TextBox1.Text, 6, 2) & ")"
Reg = Application.VLookup(Mid(TextBox1.Text, 6, 2), Range("M1:O96"), 3, False)
Label15.Caption = Reg
'On Error Resume Next
CommNaiss = Application.VLookup(CLng(Mid(TextBox1.Text, 6, 5)), Range("AV1:AW36529"), 2, False) 'That's the line I get an error if value does't exist....
所以,如果有錯誤,你想告訴用戶,而不是'恢復下一個'? –
我回滾了你的編輯。請勿將您的解決方案發布在您的帖子正文中。隨意在其他人之間發佈您的答案,或者通過提升/標記答案爲已接受的方式評分另一張海報。 – CubeJockey