答案 0 :(得分:0)
幸运的是,Excel VBA提供了一个相当方便的“功能”来获取下一个可用空间
Sub copyToFreeSpace()
Dim copyRange As Range
Dim xSheet As Worksheet
Dim freeRow As Long
Set xSheet = ThisWorkbook.Worksheets("TABLENAME") 'Set the Worksheet here
Set copyRange = xSheet.Range("A1:D1") 'Define Range
freeRow = xSheet.Cells(xSheet.Rows.Count, 1).End(xlUp).Row + 1 'Get "free row"
xSheet.Range(xSheet.Cells(freeRow, 1), xSheet.Cells(freeRow, 4)) = copyRange.Value 'Copy value from above range
End Sub
答案 1 :(得分:0)
价值转移更快!同样,由于这将在循环内,因此每次都需要重新调整最后一个空闲行,否则您将连续粘贴相同的值。
以下是示例代码,它在递增最后一行时循环了48次
Option Explicit
Sub ValueTransfer()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<-- Update
Dim rCopy As Range, LR As Long, i As Long
Set rCopy = ws.Range("A1:D1")
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Offset(1).Row
For i = 2 To 50
ws.Range("A" & LR).Resize(1, 4).Value = rCopy.Value
LR = LR + 1
Next i
End Sub
作为额外的好处,您可以通过将Resize
函数更改为
`.Resize(rCopy.Rows.Count, rCopy.Columns.Count)