PC Review


Reply
Thread Tools Rate Thread

combining operators

 
 
=?Utf-8?B?ZXppbA==?=
Guest
Posts: n/a
 
      23rd Jul 2007
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 With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      23rd Jul 2007
> 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

 
Reply With Quote
 
dq
Guest
Posts: n/a
 
      23rd Jul 2007
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

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      23rd Jul 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining operators fgwiii Microsoft Access Queries 3 15th Jun 2009 04:27 PM
static member operators vs non-member operators Ioannis Vranos Microsoft VC .NET 0 25th Oct 2004 05:58 PM
Operators =?Utf-8?B?SHk=?= Microsoft Access Queries 2 9th Mar 2004 02:25 PM
account operators reseting passwords for other account operators? Bob Gilbreath Microsoft Windows 2000 Active Directory 3 4th Feb 2004 09:32 AM
Account Operators can't manage other Account Operators account Mikael Oskarsson Microsoft Windows 2000 Active Directory 2 22nd Aug 2003 07:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:38 PM.