Excel VBA用户定义的函数:调用工作表函数中的单元格

我在Excel中有一个用户定义的函数,我在多个工作表中运行。 我正在尝试使用Cells(i, j)来拉动单元格的行和列在我的函数被调用的表中的值 。 相反,当我点击“立即计算”button时, Cells(i, j)活动工作表中单元格[i,j]的值拉出,并且自动计算不起作用。

我究竟做错了什么?

完整的function在下面,不知道是否需要回答我的问题。

 Option Explicit Option Base 1 Option Compare Text Function recordString(ByVal width As Integer, ByVal height As Integer, ByVal firstCell As Range) As String Application.Volatile Dim tempString As String tempString = "" Dim i As Integer Dim j As Integer For i = firstCell.Row To firstCell.Row + height - 1 For j = firstCell.Column To firstCell.Column + width - 1 If IsEmpty(Cells(i, j)) Then tempString = tempString & "0" Else tempString = tempString & "1" End If Next j Next i recordString = tempString End Function 

您需要使用Application.Caller。

这将返回函数input的表单的A1单元格中的值:

 Public Function DisplayCaller() As String DisplayCaller = Application.Caller.Parent.Cells(1, 1) End Function 

这将返callback用表的名称:

 Public Function DisplayCaller() As String DisplayCaller = Application.Caller.Parent.Name End Function 

欲了解更多信息:
http://www.cpearson.com/excel/sheetref.htm