我无法弄清楚如何处理在我的宏中引发的错误。通过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