简体   繁体   English

如何复制和粘贴总是下面的一行

[英]How to copy and paste always one row below

I have been working on code to copy and paste from one worksheet to another.我一直在研究从一个工作表复制和粘贴到另一个工作表的代码。 The data that I need to copy will always be at A1:E1 , however, I need to always paste one row below.我需要复制的数据总是在A1:E1 ,但是,我需要总是在下面粘贴一行。 I will run it everyday, so for instance if today I paste on cells A1:E1 , then tomorrow I would need to paste on A2:E2 and on the next day A3:E3 ... I wrote the code below which works but is not as dynamic as I need it to be.我会每天运行它,例如,如果今天我粘贴在单元格A1:E1 ,那么明天我需要粘贴在A2:E2和第二天A3:E3 ......我写了下面的代码,但它是有效的不像我需要的那样动态。 I would appreciate your help我很感激你的帮助

Thank you谢谢

Sub Copy_range()

Worksheets("Dividends").Range("A1:E1").copy

Worksheets("Draft").Range("A1:E1").PasteSpecial
End Sub

This will make it more modular by skipping down past all used cells then pasting the value on the next empty cell.通过跳过所有使用过的单元格然后将值粘贴到下一个空单元格上,这将使其更加模块化。

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.

相关问题 循环复制和粘贴总是下面的一行 - loop to copy and paste always one row below VBA复制并粘贴到下面的第+1行 - VBA Copy and Paste to Row +1 below 如何复制最后一行数据的范围并粘贴到它下面的行中 - How To Copy Range of Last Row of Data and Paste into Row below It VBA:识别工作表中的最后一行公式(或数据),复制该行,然后在其正下方粘贴一行 - VBA: Identify Last row of formulas (or data) in sheet, copy that row, and then paste one row right below it 复制并粘贴在黄色突出显示的行下方 - Copy and paste below the yellow highlighted row 将单元格复制并粘贴到VBA循环下面的行中 - Copy and Paste Cell into row below VBA Loop 如果行为空,如何从其下面的行复制/粘贴数据以填充空行? - If a row is empty, how do I copy/paste data from the row below it to populate the empty row? VBA 不起作用(从一个文件复制数据并粘贴到最后一行数据下方的不同工作簿) - VBA not working (copy data from one file and paste to different workbook below last row of data) VBA代码可从一个工作表复制数据并将其粘贴到另一工作表的最后一行下方 - VBA code to copy data from one worksheet & paste below last row of another worksheet 在工作表 3 中复制范围 A:AM 而不是整行并粘贴到工作表 1 (A1) 中的一个下方 - Copy range A:AM in sheet 3 instead of entire row and paste in sheet1 (A1) one below the other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM