【发布时间】:2018-11-27 20:00:14
【问题描述】:
我创建了用户定义的函数来计算足球比赛结果。
我的根函数看起来是:
Function calculatePoints(personTypes As Range, matchesResults As Range) As Integer
calculatePoints = getAllPersonPoints(personTypes, matchesResults)
End Function
getAllPersonPoints 函数:
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
当我尝试通过手动设置参数来调用此函数时:personTypes range 和 matchesResults ragne -everythink 工作正常。
但是当我试图从工作表中调用它时,我在选定的单元格中出现#VALUE 错误。
但在函数形式中,结果是正确的:
A 一直在尝试调试返回值,但我总是得到正确的值。我的问题只是返回单元格中的错误。
有什么想法吗?
【问题讨论】:
-
为什么你有一个单独的函数
calculatePoints除了调用另一个函数之外什么都不做?