Copy Paste VBA Macro

naturegal27

New Member
Joined
Sep 3, 2017
Messages
4
Help!

I have a macro on a button to copy and paste a range into a new worksheet. I need it to add a new line so that every time a user click, a new line of data will be added. Help!

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

Set copySheet = Worksheets("Final")
Set pasteSheet = Worksheets("Raw Data")

copySheet.Range("Raw").Copy
pasteSheet.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
Private Sub CommandButton1_Click()

 Application.ScreenUpdating = False

Dim lRow As Long
            lRow = Sheets("Raw Data").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row

            Set r = ActiveWorkbook.Names("Raw").RefersToRange

 Sheets("Raw Data").Range("A" & lRow & ":" & Cells(lRow + r.Rows.Count - 1, r.Columns.Count).Address).Value = Sheets("Final").Range("Raw").Value

Application.ScreenUpdating = True

 End Sub
 
Upvote 0
Wrong
 
Last edited:
Upvote 0
Alternatively, if you have formulas in the original range try
Code:
Private Sub CommandButton1_Click()

Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim NxtRow As Long
    Dim Rng As Range
    
    Set copySheet = Worksheets("Data")
    Set pasteSheet = Worksheets("Sheet3")
    Set Rng = Range("Raw")
    
    With pasteSheet
        NxtRow = .Cells.Find("*", After:=.Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Offset(1).Row
        .Range("A" & NxtRow).Resize(Rng.Rows.Count, Rng.Columns.Count).Value = Rng.Value
    End With
    
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top