VBA未提交的子错误结束

我发现下面的VBA代码来总结彩色单元格,但是在倒数第二行我得到了一个意外的语句错误结束:

Function SumByColor(CellColor As Range, SumRange As Range) Application.Volatile Dim ICol As Integer Dim TCell As Range ICol = CellColor.Interior.ColorIndex For Each TCell In SumRange If ICol = TCell.Interior.ColorIndex Then SumByColor = SumByColor + TCell.Value End If Next TCell End Function Sub Count_red() =SumByColor(AC4,J2:AK1725) End Sub 

编辑:我调整了最后一点根据你的build议

Sub Count_red() Function Count_red() As Double Count_red = SumByColor([AC4], [J2:A1725]) End Function End Sub

当我尝试运行代码时出现新的错误消息:“检测到模糊名称:Count_red()”

 Sub Count_red() =SumByColor(AC4,J2:AK1725) End Sub 

是一无所获。

根据名字,我猜它应该是

 Function Count_red() Count_red=SumByColor([AC4],[J2:AK1725]) End Function