所以我有两张纸。这两个都是名册。其中一个日期在顶部,左侧是名字。另一个是相反的。我需要将后者的数据复制到前者。我可以将复制单元硬编码到单元格,问题是工作人员从名册到名册的变化。完成此任务的最佳方法是什么?
答案 0 :(得分:1)
这样的事情:
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
编辑:我发现你过去曾提交过很好的问题以及代码,所以我猜它已经迟到了: - )