• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using IF Function in VBA

KishorKK

Member
Hi,

I am using if function by using this i would like to get result if any one of subject failed then he should be consider fail like this, im trying but not getting some one please help me


Sub basic_if5()

Please tell me where i am going wrong?

find it here in this. Thanks
 

Attachments

If you want any fail to cause a fail then the only way to get a pass is to use And

eg:

Code:
Sub basic_if5()

If Range("a2").Value <= 40 And Range("b2").Value <= 40 And Range("c2").Value <= 40 And Range("d2") <= 40 Then
  Range("e2").Value = "Pass"
Else
  Range("e2").Value = "Fail"
End If

End Sub
 
Hello Kishore.

The only differences between "And" , "OR" would Operator "And" ensure to match all the conditions whereas "OR" any one of the condition matches then code executes.

Hope this helps.

Sub Kishore()
If Range("a2").Value <= 40 or Range("b2").Value <= 40 orRange("c2").Value <= 40 or Range("d2") <= 40 Then
Range("e2").Value = "Pass"
Else
Range("e2").Value = "Fail"
EndIf

EndSub
 
Back
Top