ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OR statement VB (https://www.excelbanter.com/excel-programming/392490-statement-vbulletin.html)

Max

OR statement VB
 
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

Mike H

OR statement VB
 
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

"Max" wrote:

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


steve_doc

OR statement VB
 
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

"Max" wrote:

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

OR statement VB
 
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


"steve_doc" wrote:

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

"Max" wrote:

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


Mike H

OR statement VB
 
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

"Max" wrote:

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


"steve_doc" wrote:

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

"Max" wrote:

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

OR statement VB
 
Thanks!

"Mike H" wrote:

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

"Max" wrote:

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


Bob Phillips

OR statement VB
 

"Mike H" wrote in message
...
Max,

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



val1 = 17
val2 = 2

MsgBox val1 20 Or val2 0



Max

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

Max

"Mike H" wrote:

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

"Max" wrote:

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


"steve_doc" wrote:

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

"Max" wrote:

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


Peter T

OR statement VB
 
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


"Max" wrote in message
...
OK, I understand and the if statement already works,
Thank you Mike!

Max

"Mike H" wrote:

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

"Max" wrote:

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


"steve_doc" wrote:

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

"Max" wrote:

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




Mike H

OR statement VB
 
if or(Sheets(1).Range("K36")16%, Sheets(1).Range("K37")16%) then
BLABLABLA


MsgBox val1 20 Or val2 0 then BLABLABLA without IF please?

Mike


"Bob Phillips" wrote:


"Mike H" wrote in message
...
Max,

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



val1 = 17
val2 = 2

MsgBox val1 20 Or val2 0




Bob Phillips

OR statement VB
 

"Mike H" wrote in message
...
if or(Sheets(1).Range("K36")16%, Sheets(1).Range("K37")16%) then
BLABLABLA


MsgBox val1 20 Or val2 0 then BLABLABLA without IF please?


val3 = -(val1 20 Or val2 0) * 20



Mike H

OR statement VB
 
That isn't providing a boolean True/False option (then
BLABLABLA) because it will always multiply by 20 (true*20=1) or(false*20=0).



Mike

"Bob Phillips" wrote:


"Mike H" wrote in message
...
if or(Sheets(1).Range("K36")16%, Sheets(1).Range("K37")16%) then
BLABLABLA


MsgBox val1 20 Or val2 0 then BLABLABLA without IF please?


val3 = -(val1 20 Or val2 0) * 20




Mike H

OR statement VB
 
before I'm corrected 1*20=20

"Mike H" wrote:

That isn't providing a boolean True/False option (then
BLABLABLA) because it will always multiply by 20 (true*20=1) or(false*20=0).



Mike

"Bob Phillips" wrote:


"Mike H" wrote in message
...
if or(Sheets(1).Range("K36")16%, Sheets(1).Range("K37")16%) then
BLABLABLA

MsgBox val1 20 Or val2 0 then BLABLABLA without IF please?


val3 = -(val1 20 Or val2 0) * 20




Bob Phillips

OR statement VB
 
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)

"Mike H" wrote in message
...
That isn't providing a boolean True/False option (then
BLABLABLA) because it will always multiply by 20 (true*20=1)
or(false*20=0).



Mike

"Bob Phillips" wrote:


"Mike H" wrote in message
...
if or(Sheets(1).Range("K36")16%, Sheets(1).Range("K37")16%) then
BLABLABLA

MsgBox val1 20 Or val2 0 then BLABLABLA without IF please?


val3 = -(val1 20 Or val2 0) * 20






Max

OR statement VB
 
Cheers guys, I've seen them all and used quite all of it!
Max

"Peter T" wrote:

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


"Max" wrote in message
...
OK, I understand and the if statement already works,
Thank you Mike!

Max

"Mike H" wrote:

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

"Max" wrote:

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


"steve_doc" wrote:

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

"Max" wrote:

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






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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com