Posted on 2013-05-09
Last Modified: 2013-05-09

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!
Question by:joyacv2
LVL 29

Assisted Solution

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

Author Comment

ID: 39154016

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

Accepted Solution

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

813 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

12 Experts available now in Live!

Get 1:1 Help Now