Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ezil,
Try: If Cells(i, "A").Value = vac And _ (Cells(i, "b") = "EQ" Or Cells(i, "b") = "BE") Then -- Hope that helps. Vergel Adriano "ezil" wrote: 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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Operators/if etc | Excel Programming | |||
Where are Bitwise Operators | Excel Worksheet Functions | |||
greater than but less than operators for VBA | Excel Programming | |||
Operators With Times | Excel Discussion (Misc queries) | |||
Unary operators | Excel Worksheet Functions |