根据名称和日期将数据从一个 sheet 复制到另一个

Copy data from one sheet to another based on names and dates

所以我有两张纸。两者都是名册。一个在顶部显示日期,在左侧显示名称。另一个则相反。我需要将数据从后者复制到前者。我可以将复制单元格硬编码到单元格,问题是从花名册到花名册的员工数量变化。完成此操作的最佳方法是什么?

像这样:

Option Explicit

Public Sub CopyTranspose(ByVal prgnSourceTopLeftCell As Excel.Range, ByVal prngDestinationTopLeftCell As Excel.Range)
    Dim lastRow As Long
    Dim lastCol As Long

    With prgnSourceTopLeftCell.Worksheet
        lastRow = .Cells(.Rows.Count, prgnSourceTopLeftCell.Column).End(xlUp).Row
        lastCol = .Cells(prgnSourceTopLeftCell.Row, .Columns.Count).End(xlToLeft).Column
        .Range(prgnSourceTopLeftCell, .Cells(lastRow, lastCol)).Copy
    End With

    prngDestinationTopLeftCell.PasteSpecial xlPasteAll, Transpose:=True

    Application.CutCopyMode = False
End Sub

Public Sub Demo()
    CopyTranspose ThisWorkbook.Worksheets("Sheet1").Cells(1, 1), ThisWorkbook.Worksheets("Sheet2").Cells(1, 1)
End Sub

编辑:我看到你过去确实提交了很好的问题和代码,所以我想只是来晚了:-)