我有以下简单的功能:
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
它不起作用。我收到以下错误:对象变量或未设置块。
on GetCustomerCount = Range(“D13”)。为什么?
答案 0 :(得分:2)
GetCustomerCount是Range
如果要为其指定新的值/范围,则需要使用set。
进行此操作 Set GetCustomerCount = Range("D13")
答案 1 :(得分:0)
我认为您需要确定范围适用的工作表,即ActiveSheet.Range(“D13”)