【发布时间】:2020-08-08 20:33:42
【问题描述】:
我是 VBA 新手,希望有人可以帮助我。我创建了一个自定义函数来汇总多个工作表中单元格的值。但是,我必须使用该函数的工作表中的单元格与我需要求和的单元格不同。例如,我需要对所有工作表中的 B2 求和,但我需要使用该函数的地方是单元格 C2。有人可以帮忙吗? 我的代码:
Function AutoSum() As Variant
AutoSum = 0
For Each ws In Worksheets
If Not ws Is Application.ThisCell.Parent Then AutoSum = AutoSum + ws.Range(Application.ThisCell.Address)
Next
End Function
【问题讨论】:
-
将要用作参数的单元格地址添加到函数中。