![]() |
combining operators
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? |
combining operators
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 |
combining operators
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 |
combining operators
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? |
All times are GMT +1. The time now is 07:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com