我有一个Excel VBA过程来创建数据表。为了简化代码,我想创建一个BreakDownTable
类。
当我尝试运行代码时,我得到运行时错误:
424 - 需要对象。
知道如何从Class中获取Cells引用吗?
Private sub CreateTable()
Dim bdTable As New BreakDownTable
bdTable.StartingPosition = Range(refEditTabel.value)
bdTable.Cell(0, 0) = "Key"
bdTable.Cell(0, 1) = "Summary”
Dim dateRange as Range
Set dateRange = Range(bdTable.Cell(2, 3), bdTable.Cell(7, 6)
…
End sub
BreakDownTable CLASS:
Private pStartingPosition As Range
Public Property Get StartingPosition() As Range
StartingPosition = pStartingPosition
End Property
Public Property Let StartingPosition(value As Range)
Set pStartingPosition = value
End Property
Public Function Cell(row As Integer, col As Integer)
Cell = Cells(pStartingPosition.row + row, pStartingPosition.Column + col)
End Function
答案 0 :(得分:0)
当您将set
分配给对象引用时,您错过了Cell
:
Set Cell = Cells(pStartingPosition.row + row, pStartingPosition.Column + col)