Trapping an Error

I am looping through some rows of data, and I am getting an error on the following line.

PatternBasedFinishToUse = WorksheetFunction.VLookup(SurfCH_ValueAndSurfCH_FixedValue, Range("PatternBasedFinTable"), 2, 0)

How could I trap this error?  Considered checking the chars it is returning... needs to be > 3 chars.  If not >3 make the whole row background color red and put the word ERROR in col A.  then move on to the next row.  I use the Goto 100  which is a marker that starts the loop over.  I know it is wrg to use Goto but have not had time to fit it to make it right..  It works for me...

Also considered and On Error Resume Next???   Any idea's
RWayneHAsked:
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.

NorieVBA ExpertCommented:
Not sure how you want to handle the error but you could try something like this.
Dim Res As Variant

    ' other code
    
    Res = Application.VLookup(SurfCH_ValueAndSurfCH_FixedValue, Range("PatternBasedFinTable"), 2, 0)
    If Not IsError(Res) Then
        PatternBasedFinishToUse = Res
    Else
        ' do whatever you want/need if the VLookup fails
    End If

Open in new window

0

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
RWayneHAuthor Commented:
Thinking through this...   and this could work...  

I would like the else to color the active row back ground red.  How would I do that and put the word ERROR in the column B of that active row?
0
RWayneHAuthor Commented:
Ok using your suggestion and Res.....  I have it working.  Now all I have to do is color the cell background red.  The following line is failing.  How would I rewrite this to color the cell?

c.Offset(0, 1).Selection.Interior.Color = 255

To place text in the cell this is working.
c.Offset(0, 1).Value = "Do not use in Lynx ERROR"

Try to something similar to make the cell red.
0
NorieVBA ExpertCommented:
Get rid of Selection.
0
RWayneHAuthor Commented:
Thanks for the help.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.