将值复制并粘贴到目标
我将从昨天的信息从一张表的数据复制到另一张历史数据表。 第一张纸实际上是一个查找公式,所以我只需要粘贴到历史表的值。 这是我写的,但是这是说最后一行不起作用。 谁能帮忙?
Option Explicit Sub Test() ' ' UpdateTablesAndCharts Macro ' ' Keyboard Shortcut: Option+Cmd+t ' Dim lngNextEmptyRow As Long Dim lngLastImportRow As Long Dim shtYstrdy As Worksheet Set shtYstrdy = ThisWorkbook.Worksheets("Yesterday") With ThisWorkbook.Worksheets("ICT Historical Crashlytics Data") lngNextEmptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 .Rows(lngNextEmptyRow).Insert Shift:=xlDown .Cells(lngNextEmptyRow, "A").Value2 = _ .Cells(lngNextEmptyRow - 1, "A").Value2 + 1 shtYstrdy.Range("AM1:AN1").Copy Cells("A" & lngNextEmptyRow).PasteSpecial xlPasteValues End With End Sub
-
Cells()格式是
Cells(Rows,Column)
你可能想要Range()。 -
只需粘贴值,直接分配就会更快。
-
单元格()缺less
.
在前面,所以它没有被分配到正确的父母表。
用这个:
Sub Test() ' ' UpdateTablesAndCharts Macro ' ' Keyboard Shortcut: Option+Cmd+t ' Dim lngNextEmptyRow As Long Dim lngLastImportRow As Long Dim shtYstrdy As Worksheet Set shtYstrdy = ThisWorkbook.Worksheets("Yesterday") With ThisWorkbook.Worksheets("ICT Historical Crashlytics Data") lngNextEmptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 .Rows(lngNextEmptyRow).Insert Shift:=xlDown .Cells(lngNextEmptyRow, "A").Value2 = _ .Cells(lngNextEmptyRow - 1, "A").Value2 + 1 .Range("A" & lngNextEmptyRow).Resize(1, 2).Value = shtYstrdy.Range("AM1:AN1").Value End With End Sub