mardi 22 septembre 2015

New function in excel

I'm very new to programming and am trying to create a new function in excel. I want it to run through a range of cells and if any cells in that range are greater than NormalValue then retrun 'too low'. If the NormalValue is greater than double the max cell value in range then return 'too high'. If neither of these are true, then return 'OK'.

This is what I have come up with so far but most of this is guesswork so would really appreciate any help on this...

Function TooHighLow(rng As range, NormalValue As Double)

  For Each cell In rng
     If Application.WorksheetFunction.Max(cell.Value) > NormalValue Then
        TooHighLow = "Too Low"

     ElseIf NormalValue > 2 * (Application.WorksheetFunction.Max(cell.Value)) Then
        TooHighLow = "Too High"

     Else
        TooHighLow = "OK"

     End If
  Next cell
End Function 

Aucun commentaire:

Enregistrer un commentaire