[英]How to copy and paste always one row below
我一直在研究从一个工作表复制和粘贴到另一个工作表的代码。 我需要复制的数据总是在A1:E1
,但是,我需要总是在下面粘贴一行。 我会每天运行它,例如,如果今天我粘贴在单元格A1:E1
,那么明天我需要粘贴在A2:E2
和第二天A3:E3
......我写了下面的代码,但它是有效的不像我需要的那样动态。 我很感激你的帮助
谢谢
Sub Copy_range()
Worksheets("Dividends").Range("A1:E1").copy
Worksheets("Draft").Range("A1:E1").PasteSpecial
End Sub
通过跳过所有使用过的单元格然后将值粘贴到下一个空单元格上,这将使其更加模块化。
Sub Copy_range()
' edit line below to change where data will be copied from
Worksheets("Dividends").Range("A1:E1").Copy ' copy the value
' select the first cell on the "Draft" sheet
Worksheets("Draft").Select
ActiveSheet.Range("A1").Select
Dim count As Integer
count = 1
'skip all used cells
Do While Not (ActiveCell.value = None)
ActiveCell.Offset(1, 0).Range("A1").Select
count = count + 1
Loop
' edit line below to change alphabetical values of where data will be placed
Worksheets("Draft").Range("A" & count & ":E" & count).PasteSpecial ' paste the value
' at Acount:Ecount where count is the current row i.e. A11:E11
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.