PGSystemTester

Excel UDF IF's Formula (available in 2016)

Jul 7th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function IFs(ParamArray Conditions() As Variant) As Variant
  2. 'This function is available in Excel 2016
  3.  
  4. '=ifs(F17<>F17,"First True",12>1,"Second True",1>2,"Third True","None True!")
  5. 'will return "Second True"
  6.  
  7. '=ifs(F17<>F17,"First True",12<1,"Second True",1>2,"Third True","None True!")
  8. 'will return "None True!"
  9.  
  10. '=ifs(F17<>F17,"First True",12<1,"Second True",1>2,"Third True")
  11. 'will return False
  12.  
  13. For i = 0 To UBound(Conditions)
  14.  
  15. If i Mod 2 = 0 Then
  16.  
  17.     If i = UBound(Conditions) Then
  18.         IFs = Conditions(i)
  19.         Exit Function
  20.     On Error GoTo BadRow
  21.     ElseIf Conditions(i) = True Then
  22.    
  23.         IFs = Conditions(i + 1)
  24.         Exit Function
  25.     ElseIf Conditions(i) <> False Then
  26.         GoTo BadRow
  27.     End If
  28.     On Error GoTo 0
  29. End If
  30.  
  31. Next i
  32.  
  33. If IsEmpty(IFs) Then IFs = False
  34.  
  35. Exit Function
  36. BadRow:
  37. IFs = "#Non True/False Result in Condition " & i + 1 & ": """ & Conditions(i) & """"
  38.  
  39. End Function
Add Comment
Please, Sign In to add comment