combining operators

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my macro I use the following line and it is working (vac is string
variable)

If Cells(i, "A").Value = vac And Cells(i, "b") = "EQ" Then

My macro needs another "OR" condition also, for that i am using

If Cells(i, "A").Value = vac And Cells(i, "b") = "EQ" or
"BE" Then

but it results in type mismatch error. How to combine "and" and "or"
conditions?
 
In my macro I use the following line and it is working (vac is string
variable)

If Cells(i, "A").Value = vac And Cells(i, "b") = "EQ" Then

My macro needs another "OR" condition also, for that i am using

If Cells(i, "A").Value = vac And Cells(i, "b") = "EQ" or
"BE" Then

but it results in type mismatch error. How to combine "and" and "or"
conditions?

You have to do each logical test separately in VB(A) and using parentheses
is always a good idea (sometimes your logic won't work correctly without
them, but including them always clarifies the logic). Try this statement
instead...

If Cells(i, "A").Value = vac And (Cells(i, "b") = "EQ" or Cells(i, "b") =
"BE") Then

Rick
 
Hallo Ezil,

You get an error because VB is trying to interpret "BE" as either true
or false and it can't.
Change the line into
If Cells(i, "A").Value = vac And (Cells(i, "b") = "EQ" or Cells(i,
"b") = "BE") Then
and it should work just fine

dq
 
Ezil,

Try:

If Cells(i, "A").Value = vac And _
(Cells(i, "b") = "EQ" Or Cells(i, "b") = "BE") Then
 

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

Back
Top