【发布时间】:2016-02-06 15:43:34
【问题描述】:
程序的功能是将vlookup的结果返回到要查找的值所在的同一单元格中,但它有两个问题。
1.如果在消息框中按“否”,它会一次又一次地返回消息框?
2。如果在空白单元格上按 Enter,我不希望出现消息框?
这里是代码
Sub Worksheet_Change(ByVal Target As Range)
Dim Ret_type As Integer
Dim strMsg As String
Dim strTitle As String
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A114")) Is Nothing Then
Application.EnableEvents = False
Table2 = Sheet2.Range("C2:D3")
strTitle = "Alert"
strMsg = "Combination not found press Yes for manual entry"
On Error Resume Next
Target.Value = Application.WorksheetFunction.VLookup(Target.Value, Table2, 2, False)
Application.EnableEvents = True
If Err.Number <> 0 Then
Ret_type = MsgBox(strMsg, vbYesNo, strTitle)
Select Case Ret_type
Case 7
ActiveCell.Offset(-1, 0).Clear
End Select
End If
On Error GoTo 0 ''no error, coming back to default conditions
End If
End Sub
【问题讨论】: