如何使用分配给按钮的代码将隐藏在表底部行中的公式复制到位于同一列中的活动单元格



>我在工作表中有一个表格,用于跟踪一个人被指派执行职责的人和时间。该表具有一个包含日期的标题行。最左边的 2 列有个人的头衔和姓名(名册(。每个日期只有一个人被分配到特定职责。表格的底行包含我要在单击按钮时复制到表格中同一列中的活动单元格的公式。我曾多次尝试完成这项任务,但都充满了错误。 任何帮助将不胜感激。

Sub PasteFormula() 
' 
' PasteFormula Macro 
' Pastes a formula from the table's bottom row, that is hidden, into the active cell of the same column. 
' 
'
ActiveCell.PasteSpecial xlPasteAllExceptBorders 
ActiveSheet.Paste 
End Sub

也许是这样的,使用ListObject的内置属性。根据需要更改工作表和表名称。

Sub PasteMyFormula()
    Dim myTbl As ListObject
    Set myTbl = ThisWorkbook.Sheets("Sheet1").ListObjects("Table1")
    With myTbl
        If Not Intersect(ActiveCell, .DataBodyRange) Is Nothing Then
            .DataBodyRange(.ListRows.Count, ActiveCell.Column).Copy
            ActiveCell.PasteSpecial xlPasteAllExceptBorders
            Application.CutCopyMode = False
        End If
    End With        
End Sub

最新更新