Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

I would like to recreate the IF statement shown as a user defined function

$
0
0

I have the below IF OR statement below, that does the job I want it to but I would prefer if I could create this as a user defined function,

Essentially, I have 2 columns of data, the columns will only ever have Red Amber or Green as their values, and I want the UDF to be able to look at both cells across the columns and return the worst case scenario, for example if one column is amber and one is green, the UDF would return Amber as that's worse than green

=IF(OR(AZ8="Red",AY8="Red"),"Red",IF(OR(AZ8="Amber",AY8="Amber"),"Amber","Green"))

This is what i have so far

Function CalculateOverallRAG(CellRef1 As Range, CellRef2 As Range,RAGStatus As String) As String

  If CellRef1 = "Red" Or CellRef2 = "Red" Then
    RAGStatus = "Red"
  ElseIf CellRef1 = "Amber" Or CellRef2 = "Amber" Then
    RAGStatus = "Amber"
  Else
    RAGStatus = "Green"
  End If

  CalculateOverallRAG = RAGStatus

End Function

Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>