I currently have a worksheet (Rego) whereby I enter data in a cell which then looks for matching data in another worksheet (Data) and returns results found to cells either as filled or blank depending on a data match result. This has worked well to date.
However I wish to advance the error handling when no data match is made.
If there is no data match I want a message box to appear stating "data not found" and then go to worksheet (Data).
Error handling is still my greatest difficulty!
I would kindly appreciate assistance and suggestions in adding instruction to my current code and achieving that result.
The current Worksheet (Rego) code is as follows...
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Protect Password:="xxxx", UserInterfaceOnly:=True
ActiveSheet.AutoFilterMode = False
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 3).Select
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -3) = Now()
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -2) = Now()
col = Left(Target.Address, 2)
If col = "$G" Then Target.Offset(0, -4) = Now()
Dim Cell As Range
If Target.Column <> 4 Then Exit Sub
Application.EnableEvents = False
For Each Cell In Target
With Cell.Offset(, 4)
If IsEmpty(Cell) Then
.ClearContents
Else
.Value = Evaluate("=VLOOKUP(""" & Cell.Value & """,'Data'!A:E,2,FALSE)")
If IsError(.Value) Then .Value = ""
End If
End With
Next Cell
Application.EnableEvents = True
(REPEATS THE LOOKUP FOR NEXT 3 CELLS)
ActiveSheet.AutoFilterMode = False
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 3).Select
ActiveSheet.Protect Password:="xxxx", UserInterfaceOnly:=True
End Sub
<!-- -->
Reply to Private Message Forward <!--
-->
However I wish to advance the error handling when no data match is made.
If there is no data match I want a message box to appear stating "data not found" and then go to worksheet (Data).
Error handling is still my greatest difficulty!
I would kindly appreciate assistance and suggestions in adding instruction to my current code and achieving that result.
The current Worksheet (Rego) code is as follows...
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Protect Password:="xxxx", UserInterfaceOnly:=True
ActiveSheet.AutoFilterMode = False
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 3).Select
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -3) = Now()
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -2) = Now()
col = Left(Target.Address, 2)
If col = "$G" Then Target.Offset(0, -4) = Now()
Dim Cell As Range
If Target.Column <> 4 Then Exit Sub
Application.EnableEvents = False
For Each Cell In Target
With Cell.Offset(, 4)
If IsEmpty(Cell) Then
.ClearContents
Else
.Value = Evaluate("=VLOOKUP(""" & Cell.Value & """,'Data'!A:E,2,FALSE)")
If IsError(.Value) Then .Value = ""
End If
End With
Next Cell
Application.EnableEvents = True
(REPEATS THE LOOKUP FOR NEXT 3 CELLS)
ActiveSheet.AutoFilterMode = False
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 3).Select
ActiveSheet.Protect Password:="xxxx", UserInterfaceOnly:=True
End Sub
<!-- -->
-->