OR statement VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

this must be very easy, but I cannot figure it out the right way:

I want an If statement that checks whether one or more cells contain
specific values. Therefore I tried something like:

if or(Sheets(1).Range("K36")>16%, Sheets(1).Range("K37")>16%) then
BLABLABLA
etc.

However, the OR doesn't work like this, but I cannot figure out how it
should be done!

Thanks for the help!

Max
 
Max,

In VB

Sub mersible()
If Range("A1").Value = 1 Or Range("A2").Value = 2 Then
MsgBox ("Validated")
Else
MsgBox ("Not Validated")
End If
End Sub

OIr as a worksheet formula:-

=IF(OR(A1=1,A2=2),"Its true","Its not true")

Mike
 
Hi Max

Standard syntax for using If Then statements is as follows

If ......... Then
dosomething
Else
do something else
End If

Or

If ......... Then
Do something
ElseIf ........
Do something Else
End If

Depending on how many logical statements you have to check - you could also
use the Selectt Case statement

HTH
 
Hi Mike,

thanks, I know about the if-statements. But I want to use OR statements, not
only here, but in other parts as well and I thought they might be available
in VB as well. Just as you can use them in excel, returning a Boolean value.
Can you help me with this one?

Thanks, Max
 
Max,

You can't use OR without IF and I gave you the VB version.

Sub mersible()
If Range("A1").Value = 1 Or Range("A2").Value = 2 Then
MsgBox ("Validated")
Else
MsgBox ("Not Validated")
End If
End Sub



Mike
 
Thanks!

Mike H said:
Max,

In VB

Sub mersible()
If Range("A1").Value = 1 Or Range("A2").Value = 2 Then
MsgBox ("Validated")
Else
MsgBox ("Not Validated")
End If
End Sub

OIr as a worksheet formula:-

=IF(OR(A1=1,A2=2),"Its true","Its not true")

Mike
 
OK, I understand and the if statement already works,
Thank you Mike!

Max
 
Max,

did you see Bob's example without use of 'If'

another one -

Dim bValid as Boolean
bValid = Range("A1").Value = 1 Or Range("A2").Value = 2

Regards,
Peter T
 
if or(Sheets(1).Range("K36")>16%, Sheets(1).Range("K37")>16%) then
MsgBox val1 > 20 Or val2 > 0 then BLABLABLA without IF please?

Mike
 
It was just an example, you can do more, but you're adamant, so I will shut
up.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top