【发布时间】:2015-06-23 16:08:27
【问题描述】:
我在 Excel 中有一个用户定义的函数,我在多个工作表中运行。我正在尝试使用Cells(i, j) 在调用我的函数的工作表中通过它们的行和列提取单元格的值。相反,当我点击“立即计算”按钮时,Cells(i, j) 会在 活动工作表 中提取单元格 [i,j] 的值,但自动计算不起作用。
我做错了什么?
完整功能如下,不知道是否需要回答我的问题。
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
【问题讨论】:
标签: vba excel user-defined-functions