How to identify which IF condition has been satisfied

abi_learn_vba

Board Regular
Joined
Nov 6, 2009
Messages
215
Hi,

I have below If Statement with three condition used with help of OR, at any point of time only one of these condition will be satisfied. Is there a way to identify which of these three OR condition has satisfied?

Code:
If Range("O" & n) = "" Or Range("O" & n) < Tdy Or Range("O" & n) = Tdy Then
'My Code
End if

Appreciate your help and support.

Thanks
-Abi
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Not the way you have it written...

You'd have to structure it with an IF ElseIf type of thing..

Code:
If Range("O" & n) = "" Then
    Msgbox "It was blank"
ElseIf Range("O" & n) < Tdy Then
    Msgbox "It was less than " & Tdy
ElseIf Range("O" & n) = Tdy Then
    Msgbox "It was equal to " & Tdy
End If
 
Upvote 0
Thanks for your reply.

My requirement was not that.

My requirement is if any of these condition is true then i am going to perform same action, which may be for 10 to 15 lines of code. And based on which ever condition among it is satisfied i am going to perform single line code. My question is without using another if condition to check the value in Range("O" & n) will i be able to perform that single line of code.

Code:
If Range("O" & n) = "" Or Range("O" & n) < Tdy Or Range("O" & n) = Tdy Then

'My Code
'
'
'Need to check which of this condition is True.
'
Elseif 'Some other Condition'

'My codes

End if

Please let me know if you did not understand this.

Thanks
-Abi
 
Upvote 0
Try this

Code:
Dim OrTrue As Boolean
OrTrue = False
If Range("O" & n) = "" Then
    Msgbox "It was blank"
    OrTrue = True
ElseIf Range("O" & n) < Tdy Then
    Msgbox "It was less than " & Tdy
    OrTrue = True
ElseIf Range("O" & n) = Tdy Then
    Msgbox "It was equal to " & Tdy
    OrTrue = True
End If
 
If OrTrue = True Then
    'My Codes here
End If
 
Upvote 0
Another approach
Code:
Dim Cond as Long

With Range("O" & n)
    Cond = (.Value = vbNullString) + 2 * (.Value < Tdy) + 3 * (.Value = Tdy)
End With

If Cond < 0 Then
    Rem do stuff
    Select Case Cond
        Case -1
            MsgBox "empty"
        Case -2
            MsgBox "LT Tdy"
        Case -3
            MsgBox "EQ Tdy"
    End Select
Else
    MsgBox "no condition met"
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top