Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
dq dq is offline
external usenet poster
 
Posts: 46
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Operators/if etc Peter[_61_] Excel Programming 4 December 18th 06 11:11 AM
Where are Bitwise Operators Dennis W. Bulgrien Excel Worksheet Functions 1 June 30th 06 05:51 PM
greater than but less than operators for VBA jsr Excel Programming 5 May 27th 06 06:08 PM
Operators With Times Michael Link Excel Discussion (Misc queries) 2 March 9th 05 02:46 PM
Unary operators Joe Excel Worksheet Functions 3 February 14th 05 06:09 PM


All times are GMT +1. The time now is 01:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"