我有这段代码,我想在另一个工作表中查找一些单元格,如果它们符合条件,则将相邻的单元格添加到合计中,这将返回到调用的单元格函数。
Function collectUtfall(A1 As String, Ax As String)
Dim rng As Range
Dim total As Long: total = 0
Set rng = Sheets("Utfall").Range("M2:O272")
Dim cell As Range
For Each cell In rng
If StrComp(cell.Offset(0, 1).Text, Ax, vbTextCompare) = 0 Then
total = total + ActiveCell.Value
Else
End If
Next
collectUtfall = total
End Function问题是在执行时,我得到了一个"Circle reference“错误。以这种方式使用ActiveCell.Value有问题吗?
如果我只是尝试一个值,比如10,它就能正常工作:
total = total + 10所以问题一定出在ActiveCell.Value上
发布于 2016-08-28 09:07:00
Function collectUtfall(A1 As String, Ax As String)
Dim rng As Range
Dim total As Long
set total = 0
Set rng = Sheets("Utfall").Range("M2:O272")
Dim cell As Range
For Each cell In rng
If StrComp(cell.Offset(0, 1).Text, Ax, vbTextCompare) = 0 Then
total = total + Cell.Value
Else
End If
Next Cell
collectUtfall = total
End Functionhttps://stackoverflow.com/questions/18525621
复制相似问题