Solved

ERROR IN ELSEIF STATEMENT

Posted on 2013-05-09
3
241 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 80

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now