Excel VB Error Message

When I run the following script, and someone puts the wrong number in the script, such as 123456789, it empties the cell but doesn't give them an error message. How can I rewrite the code to not only empty the cell, but give them an error message as well?

Sub worksheet_change(ByVal target As Range)
Dim myrng  As Range
Set myrng = Range(Sheets("Verification Edit Form").[B9], Sheets("Verification Edit Form").[B65536])
If Not Intersect(target, myrng) Is Nothing Then
    Select Case target.Value
        Case 0, 123456789, 987654321, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789
            target = ""
    End Select
    If Len(target) <> 9 Then
            target = ""
    End If
End If
End Sub
aeonflux2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zorvek (Kevin Jones)ConsultantCommented:
Sub worksheet_change(ByVal target As Range)
Dim myrng  As Range
Set myrng = Range(Sheets("Verification Edit Form").[B9], Sheets("Verification Edit Form").[B65536])
If Not Intersect(target, myrng) Is Nothing Then
    Select Case target.Value
        Case 0, 123456789, 987654321, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789
            target = ""
            MsgBox "Invalid entry."
    End Select
    If Len(target) <> 9 Then
            target = ""
            MsgBox "Entry must be nine digits."
    End If
End If
End Sub

Kevin
aeonflux2Author Commented:
When I put this code in, it gives me a neverending loop of "Entry must be nine digits." I had cntrl-alt-delete to get it to shut down. What did I do wrong?
zorvek (Kevin Jones)ConsultantCommented:
Try:

Sub worksheet_change(ByVal target As Range)
Dim myrng  As Range
Application.EnableEvents = False
Set myrng = Range(Sheets("Verification Edit Form").[B9], Sheets("Verification Edit Form").[B65536])
If Not Intersect(target, myrng) Is Nothing Then
    Select Case target.Value
        Case 0, 123456789, 987654321, 222222222, 333333333, 444444444, 555555555, 666666666, 777777777, 888888888, 999999999, 123456789
            target = ""
            MsgBox "Invalid entry."
    End Select
    If Len(target) <> 9 Then
            target = ""
            MsgBox "Entry must be nine digits."
    End If
End If
Application.EnableEvents = True
End Sub

Kevin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aeonflux2Author Commented:
YOU ARE AWESOME! Thank you, thank you, thank you, thank you!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.