Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparison problem 2

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
For some reason I can't get a comparison to work on more than one item.

I have to determine if a number is even and if its not notify the user. The problem is that for whatever reason this simply doesn't work.

Several different things have been tried but all of them fail unless they are by themselves.

Examples of success:
if A <> 0 Then do something
if A <> 2 Then do something

Examples of failure:
if A <> 0 Or A <> 2 Or A <> 4 Or A <> 6 Or A <> 8 Then do something
if A <> (0 Or 2 Or 4 Or 6 Or 8) Then do something
if A <> (0,2,4,6,8) Then do something
if A <> (Or(0,2,4,6,8)) Then do something

 
HI,

Are you absolutely sure that OR is the operator you want?

I think you might want AND if you want to say, for instance, if A is not one of these: 0,2,4,6,8 then do something.

I'd make an exclusion list, then

if(ISNA(match(A,ExclusionList,0)),do something,something else)

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
I sort of lost track that we were in the VBA forum.

Code:
Select Case A
   Case 0,2,4,6,8
   Case Else
      X = "something else"
End Select

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
If you don't want to hard-code the values, you may consider this:

Code:
Dim A As Integer

A = 4

If [blue]A Mod 2 = 0[/blue] Then
    MsgBox A & " is even"
Else
    MsgBox A & " is NOT even"
End If

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top