Solved

ERROR IN ELSEIF STATEMENT

Posted on 2013-05-09
3
245 Views
Last Modified: 2013-05-09
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!
0
Comment
Question by:joyacv2
3 Comments
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 150 total points
ID: 39154011
How about
ElseIf sht.Index > 3 And sht.Name Like "SN*-*" then
0
 
LVL 1

Author Comment

by:joyacv2
ID: 39154016
Hi,

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

Accepted Solution

by:
byundt earned 350 total points
ID: 39154117
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question