簡體   English   中英

如何復制和粘貼總是下面的一行

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM