使用细胞
我得到了以下简单的函数:
Public Function AddFields(field1 As Range, field2 As Range) As String
AddFields = "=" + field1.Address + "+" + field2.Address
End Function
Private Function GetCustomerCount(monthNumber As Integer) As Range
If monthNumber < 6 Then
GetCustomerCount = Range("D13")
ElseIf monthNumber < 12 Then
GetCustomerCount = Range("D14")
Else
GetCustomerCount = Range("D15")
End If
End Function
我从以下子函数中调用它:
Private Sub mDateLooper_OnMonth(looper As DateLooper)
Cells(looper.Row, looper.Column).Value = "Månad " & CStr(looper.MonthIndex + 1)
Cells(looper.Row + 1, looper.Column).Value = AddFields(GetCustomerCount(looper.MonthIndex + 1), Range("m21"))
Cells(looper.Row + 2, looper.Column).Value = AddFields(Cells(looper.Row + 1, looper.Column - 1), Cells(looper.Row, looper.Column))
End Sub
它不起作用。我收到以下错误:对象变量或未设置块。
GetCustomerCount = Range("D13")。
为什么?
I got the following simple functions:
Public Function AddFields(field1 As Range, field2 As Range) As String
AddFields = "=" + field1.Address + "+" + field2.Address
End Function
Private Function GetCustomerCount(monthNumber As Integer) As Range
If monthNumber < 6 Then
GetCustomerCount = Range("D13")
ElseIf monthNumber < 12 Then
GetCustomerCount = Range("D14")
Else
GetCustomerCount = Range("D15")
End If
End Function
Which I call from the following sub:
Private Sub mDateLooper_OnMonth(looper As DateLooper)
Cells(looper.Row, looper.Column).Value = "Månad " & CStr(looper.MonthIndex + 1)
Cells(looper.Row + 1, looper.Column).Value = AddFields(GetCustomerCount(looper.MonthIndex + 1), Range("m21"))
Cells(looper.Row + 2, looper.Column).Value = AddFields(Cells(looper.Row + 1, looper.Column - 1), Cells(looper.Row, looper.Column))
End Sub
It doesn't work. I get the following error: Object variable or with block not set.
on GetCustomerCount = Range("D13").
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GetCustomerCount 是一个
Range
如果您想为其分配一个新的值/范围,您需要使用 set 来执行此操作。
GetCustomerCount is a
Range
If you want to assign it a new Value / Range you need to do this with set.
我相信您需要确定范围适用于哪个工作表,即 ActiveSheet.Range("D13")
I believe you need to identify which sheet the Range applies to, i.e. ActiveSheet.Range("D13")