Worksheet Event Excel VBA

Hello,

I have a worksheet change event code I need to make. if users enters "=Sum(2+3") in a cell, it works fine. But if uswers enter something like this, in a cell
"=Su(1+2)"
it leads to "#Name?" in cell.

How do i capture this error in VBA code?

Thank you
RayneAsked:
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.

RayneAuthor Commented:
RayneAuthor Commented:
how to capture that formula error in vba worksheet change code?

thank you
DougCommented:
Try this:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
 
If Application.WorksheetFunction.IsErr(Target) Then
    Debug.Print "There is an error"
End If

End Sub

Open in new window


[Edit]
You can replace the debug.print statement with whatever you want to do to capture (e.g., show a message box, enter a value in another cell).

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
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Or you may try this....

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If IsError(Target) Then
   MsgBox "The cell content produced an error.", vbExclamation, "Error!"
   Target.Interior.ColorIndex = 3
Else
   Target.Interior.ColorIndex = xlNone
End If
End Sub

Open in new window

RayneAuthor Commented:
thank you all :)
DougCommented:
Happy to help.
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
Microsoft Excel

From novice to tech pro — start learning today.