Question about using AND or OR with If-Then statements

T

TBA

Windows 2k Pro
Excel 2000

What is the syntax for this situation:

If a = x and b = y Then
Code:
End If

Apparently the above doesn't work.  All help appreciated.

-gk-
 
N

Norman Harker

Hi TBA!

Try:

Sub test()
If Range("A4") = 7 And Range("B4") = 4 Then
Range("C4") = 11
End If
End Sub

Same principle would apply to Or

But what is your specific problem as you seem to have it OK?
--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
[email protected]
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
T

TBA

Silly me...

I had tried this

If a = 5 OR 7 OR 9 Then
......

doh!!

Thanks for the slap upside the head. ;)

-gk-

Norman Harker said:
Hi TBA!

Try:

Sub test()
If Range("A4") = 7 And Range("B4") = 4 Then
Range("C4") = 11
End If
End Sub

Same principle would apply to Or

But what is your specific problem as you seem to have it OK?
--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
[email protected]
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
TBA said:
Windows 2k Pro
Excel 2000

What is the syntax for this situation:

If a = x and b = y Then
Code:
End If

Apparently the above doesn't work.  All help appreciated.

-gk-
[/QUOTE]
[/QUOTE]
 
N

Norman Harker

Hi TBA!

Thanks for thanks and confirmation it works OK is always useful for
searchers.

We don't award slaps upside the heads on these groups except to
ourselves. Good job as I'd be like a cod on Saturday night in Halifax
by now; well and truly battered!

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
[email protected]
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
TBA said:
Silly me...

I had tried this

If a = 5 OR 7 OR 9 Then
.....

doh!!

Thanks for the slap upside the head. ;)

-gk-

Norman Harker said:
Hi TBA!

Try:

Sub test()
If Range("A4") = 7 And Range("B4") = 4 Then
Range("C4") = 11
End If
End Sub

Same principle would apply to Or

But what is your specific problem as you seem to have it OK?
--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
[email protected]
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
TBA said:
Windows 2k Pro
Excel 2000

What is the syntax for this situation:

If a = x and b = y Then
Code:
End If

Apparently the above doesn't work.  All help appreciated.

-gk-
[/QUOTE]
[/QUOTE]
[/QUOTE]
 
P

Patrick Molloy

As is the code sample is fine. Why do you think that it
does not work?


Sub test()
Dim a As Long, b As Long, x As Long, y As Long
a = 5
x = 5
b = 3
y = 3
If a = x And b = y Then
MsgBox "hello world!"
End If
End Sub
 
Top