Error handling in macro

Giganews Newsgroups
Subject: Error handling in macro
Posted by:  michaelberrier (michaelberri…
Date: 23 May 2006

I have a macro that displays a message box if a formula result is true,
and calls another macro if it is false using an "IF..Then..Else" line.
The True/False is based on a specially formatted date being compared to
data in that cell, but there are time when a user will enter a word or
phrase in the comparison box, producing a #VALUE in the cell that the
macro doesn't recognize.  I'm guessing this means I will need an error
handler in the macro to deal with that, and I've tried several, but I
can't get it to work.  Bottom line, I need the message box to appear if
the value is True(as above and works great), and the macro from Module
22 to run if anything else appears in that cell.
Thanks to all.

Here is the code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Target.Cells.Count > 1 Then Exit Sub 'only one cell at a time

    'exit unless it Is D7 that changed
    If Intersect(Target, Me.Range("$D$7")) Is Nothing Then Exit Sub

    If IsEmpty(Target.Value) Then Exit Sub
If Range("d4") = True Then
MsgBox "Check Driver's License Expiration Date", 48, "Exprired Driver's
    Call Module22.Look_Here1
    'the macro To Call when D7 changes

    End If

    End Sub