line code modification

  • Thread starter TUNGANA KURMA RAJU
  • Start date
T

TUNGANA KURMA RAJU

I have a line code
If my ShtName = mstrSht And arrVal(0) = "EQ" Then
Sheets(mstrSht) .Activate
I would like change the condition And arrVal(0) ="EQ" or "BE"
I am quite new to vba,how to modify the above line code.Thanks.
 
T

TUNGANA KURMA RAJU

Thank you so much.
if 2 or more 'or' conditions can I use 'any' condition ?
 
V

Vergel Adriano

Tungana,

Yes, you can put 'any' condition. By 'any' I assume you're asking if you
can validate more than one variable in the same If condition set. The
important thing when working with And and Or logical operators is that you
group them right. For exampe, this:

i=3 And j=1 Or b=1

is not the same as this:

i=3 And (j=1 Or b=1)

Sometimes if there's too many conditions, it makes sense to nest the If
conditions to break them down and make it easier to understand. For example,
using your code, you can also do it this way:

If myShtName = mstrSht Then
If arrVal(0) = "EQ" Or arrVal(0) = "BE" Then
'do something
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top