Excel VBA - Two IFs

Dear Experts,

Could you please a have a short look on this code part:

ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
If ErrMes Is Nothing Then GoTo NoChangeMessage
Else
    ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
    If InStr(1, ErrMes, "change", vbTextCompare) > 0 Then
    session.findById("wnd[2]/tbar[0]/btn[0]").press
    End If
End If

NoChangeMessage:

Open in new window


its contains two IFs but somehow bringing error message that 'Else without If', could you please advise where its syntax is incorrect exactly?

Thanks in advance,
LVL 1
csehzIT consultantAsked:
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.

Shaun VermaakTechnical Specialist/DeveloperCommented:
This is seen as a complete if statement
If ErrMes Is Nothing Then GoTo NoChangeMessage

Open in new window


Change it to this
ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
If ErrMes Is Nothing Then
    GoTo NoChangeMessage
Else
    ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
    If InStr(1, ErrMes, "change", vbTextCompare) > 0 Then
        session.findById("wnd[2]/tbar[0]/btn[0]").press
    End If
End If

NoChangeMessage:

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
csehzIT consultantAuthor Commented:
Thank you for that
0
Thomas UCommented:
Hi csehz

goto nochangemessage on a new line:

ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
If ErrMes Is Nothing Then
GoTo NoChangeMessage
Else
    ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
    If InStr(1, ErrMes, "change", vbTextCompare) > 0 Then
    session.findById("wnd[2]/tbar[0]/btn[0]").press
    End If
End If

NoChangeMessage:
0
Thomas UCommented:
wow...tha was fast...lol :)
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You can write it like this...

ErrMes = session.findById("wnd[2]/usr/txtMESSTXT1").Text
If ErrMes Is Nothing Then GoTo NoChangeMessage
If InStr(1, ErrMes, "change", vbTextCompare) > 0 Then
    session.findById("wnd[2]/tbar[0]/btn[0]").press
End If
NoChangeMessage:

Open in new window

1
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
VBA

From novice to tech pro — start learning today.