ERROR IN ELSEIF STATEMENT

Hi,

I have a code that verifies the index of a sheet. In this case, the index is 4 and the sheet name is SN 300-3

i have the following line:

ElseIf sht.Index > 3 And InStr(1, sht.Name, "-") And InStr(1, sht.Name, "SN") then

and returns false. I don't know why is happening? I test the statement individually and works well but when i mix the three doesn't work! Only works two by two!
LVL 1
joyacv2Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
byundtConnect With a Mentor Commented:
The ElseIf statement is expecting a True or False result--but you are calculating the result of a Boolean (sht.Index > 3) with two integers (the InStr). If you force the two InStr to return a Boolean value, then your statement will work:
ElseIf (sht.Index > 3 And InStr(1, sht.Name, "-") > 0 And InStr(1, sht.Name, "SN") > 0) Then
0
 
IrogSintaConnect With a Mentor Commented:
How about
ElseIf sht.Index > 3 And sht.Name Like "SN*-*" then
0
 
joyacv2Author Commented:
Hi,

It's works perfect, but did you know why my line of code doesn't work?
0
All Courses

From novice to tech pro — start learning today.