VBA 复制并粘贴到下面的第 +1 行
VBA Copy and Paste to Row +1 below
我正在尝试编写一些代码,将单元格 A3:A6 中的数据复制并粘贴到 A8:A11,然后当再次 运行 时,它将把它粘贴到下面的行 +1 ,所以下一次是 运行 时,A8:A11 中的数据将被复制并粘贴到 A13:A16 中,下一次是 运行 时,它将把数据粘贴到 A13:16 到 A18:21 等等。
以下是我试图想出的,但我可能还有很长的路要走,任何指导将不胜感激:
Sub RollFile()
Dim UsdRows As Long
UsdRows = Cells(Rows.Count, 3).End(xlToUp).Row
With Range(Cells(1, UsdRows), Cells(UsdRows, 1))
.Copy .Offset(, 1)
.Value = .Value
.Offset(-1, 1)(1).Select
End With
End Sub
非常感谢
我建议如下:
Option Explicit
Public Sub RollFile()
Const RowsToCopy As Long = 4 'amount of rows that should be copied
Dim LastCell As Range
Set LastCell = Cells(Rows.Count, "A").End(xlUp) 'last cell in col A
With LastCell.Offset(RowOffset:=-RowsToCopy + 1).Resize(RowSize:=RowsToCopy) '= last 4 cells (4 = RowsToCopy)
.Copy LastCell.Offset(RowOffset:=2)
.Value = .Value 'not needed I think
End With
End Sub
它在 A 列中查找最后使用的单元格。然后从那里选择前 4 个单元格并复制下面的 2 行。
请注意,我认为根本不需要 .Value = .Value
,因为只有复制需要转换为值的公式才有意义。
你可以试试这个
Sub RollFile()
With Cells(Rows.Count, 1).End(xlUp) ' reference column A last not empty cell
With Range(.End(xlUp), .Cells) ' reference the range from referenced cell up to last adjacent one
.Offset(.Rows.Count + 1).Value = .Value ' copy referenced range values to a range two row below its end
End With
End With
End Sub
我正在尝试编写一些代码,将单元格 A3:A6 中的数据复制并粘贴到 A8:A11,然后当再次 运行 时,它将把它粘贴到下面的行 +1 ,所以下一次是 运行 时,A8:A11 中的数据将被复制并粘贴到 A13:A16 中,下一次是 运行 时,它将把数据粘贴到 A13:16 到 A18:21 等等。
以下是我试图想出的,但我可能还有很长的路要走,任何指导将不胜感激:
Sub RollFile()
Dim UsdRows As Long
UsdRows = Cells(Rows.Count, 3).End(xlToUp).Row
With Range(Cells(1, UsdRows), Cells(UsdRows, 1))
.Copy .Offset(, 1)
.Value = .Value
.Offset(-1, 1)(1).Select
End With
End Sub
非常感谢
我建议如下:
Option Explicit
Public Sub RollFile()
Const RowsToCopy As Long = 4 'amount of rows that should be copied
Dim LastCell As Range
Set LastCell = Cells(Rows.Count, "A").End(xlUp) 'last cell in col A
With LastCell.Offset(RowOffset:=-RowsToCopy + 1).Resize(RowSize:=RowsToCopy) '= last 4 cells (4 = RowsToCopy)
.Copy LastCell.Offset(RowOffset:=2)
.Value = .Value 'not needed I think
End With
End Sub
它在 A 列中查找最后使用的单元格。然后从那里选择前 4 个单元格并复制下面的 2 行。
请注意,我认为根本不需要 .Value = .Value
,因为只有复制需要转换为值的公式才有意义。
你可以试试这个
Sub RollFile()
With Cells(Rows.Count, 1).End(xlUp) ' reference column A last not empty cell
With Range(.End(xlUp), .Cells) ' reference the range from referenced cell up to last adjacent one
.Offset(.Rows.Count + 1).Value = .Value ' copy referenced range values to a range two row below its end
End With
End With
End Sub