0

i have created user defined function to calculate football match results.

My Root Function looks that:

Function calculatePoints(personTypes As Range, matchesResults As Range) As Integer
    calculatePoints = getAllPersonPoints(personTypes, matchesResults)
End Function

getAllPersonPoints function:

Private Function getAllPersonPoints(personTypes As Range, matchesResults 
AsRange) As Integer
    Dim x As Long
    Dim y As Long
    Dim isTheSurest As Boolean
    getAllPersonPoints = 0

    For x = 1 To personTypes.Rows.Count
        For y = 1 To personTypes.Columns.Count
            isTheSurest = isTheSurestResult(personTypes.Cells(x, 
y).DisplayFormat.Interior.PatternColorIndex)
            getAllPersonPoints = getAllPersonPoints + 
getPoints(matchesResults.Cells(x, y).Value, personTypes.Cells(x, y).Value, 
isTheSurest)
        Next y
    Next x
End Function

When i am trying to call this function by setting manually parameters: personTypes range and matchesResults ragne - everythink works fine.

But when i am trying to call it from sheet i got #VALUE error in selected cell.

#VALUE error at cell

But at function form there is correct result:

Correct value returned by function

A have been trying to debug return value and always i got correct value. I have problem only with error in return cell.

Any ideas ?

1
  • Why do you have a separate function calculatePoints that does nothing except call another function? Commented Jun 18, 2018 at 23:25

2 Answers 2

2

The issue is that DisplayFormat object does not work with UDF's

See MSDN article

The usual solution to this is to evaluate the Conditional Format conditions to determine which one is active. For example, see cpearson.com

Sign up to request clarification or add additional context in comments.

Comments

0

I resolved problem by code:

personTypes.Cells(x, y).Interior.ColorIndex

instead of:

personTypes.Cells(x,y).DisplayFormat.Interior.PatternColorIndex

This solution works.

1 Comment

You realise that doesn't detect conditional format colors, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.