lundi 21 septembre 2015

VBA Function for If statement with multiple components

I am trying to create a function (=StatusExpected) that will return pass/fail after evaluating multiple components. To be specific, 4 components (Size,Liquidity,Qualification,Exception) return "Pass/Fail". If all four return "Pass", I would like StatusExpected="Pass". If one or more of these components return "Fail", I would like StatusExpected="Fail".

StatusExpected populates I7:I506, and the 4 variables populate each row, straight across in J,AB,AF,AP respectively. I did not think this should matter however, as I am looking for a formula with 4 inputs. If you could, please also reply with whether you need to activate a cell, or if you need to define variables. Please start the code from the beginning with the Function line, as if nothing else exists. Below is what I have that isn't working:

Function StatusExpected(Size As String, Liquidity As String, Qualified As String, Exception As String)
    Range("A1").Select.Activate
    If Size = "Pass" And Liquidity = "Pass" And Qualified = "Pass" And Exception = "Pass" Then
        StatusExpected = "Pass"
    Else
        StatusExpected = "Fail"
    End If
End Function

Please provide me with anything that could help me in addition to my question, as well as best practices for clarity. Thanks!

Aucun commentaire:

Enregistrer un commentaire