[英]Return Cells reference from a VBA Class
I have an Excel VBA Procedure to create a data-table. 我有一个创建数据表的Excel VBA过程。 To simplify the code I want to create a
BreakDownTable
class. 为了简化代码,我想创建一个
BreakDownTable
类。
When I'm trying to run the code I get Run-time error: 当我尝试运行代码时,出现运行时错误:
424 – Object required.
424 –必需的对象。
Any idea how to get the Cells reference from the Class? 任何想法如何从类获取单元格引用?
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: BreakDownTable类别:
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
当您将Cell
分配给对象引用时,您缺少一个set
:
Set Cell = Cells(pStartingPosition.row + row, pStartingPosition.Column + col)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.