简体   繁体   中英

How to paste data from one sheet to another and add a new row if there's already a value in using VBA Excel?

I'm extremely new to VBAs and cannot figure out how to add a value to the next row if there's already data previous row. I'm sure I'm overthinking it, but I cannot seem to figure it out. Any help would be appreciated.

Below is the macro I'm using. Not sure if I need to offset the data or maybe add an if then statement of some sort.

Sub Archive_2()
Range("A2").Select
Selection.Copy
Sheets("Campaign Rate").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End Sub

Use below sub-

Sub CopyPaste()
Dim sh As Worksheet
Dim lRng As Range

    Set sh = Worksheets("Campaign Rate")
    Set lRng = sh.Cells(sh.Rows.Count, 1).End(xlUp)
    
    Range("A2").Copy
    lRng.Offset(1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False


Set sh = Nothing
Set lRng = Nothing
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM