Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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



  #9   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default 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

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
If statement or lookup statement not sure Renegade40 Excel Worksheet Functions 2 January 18th 09 06:11 AM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"