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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,215,268
Messages
6,123,970
Members
449,137
Latest member
yeti1016

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