Adding "1" to row when copying data range from one sheet to another

allstarsosa

New Member
Joined
Dec 5, 2018
Messages
2
Currently I have a pretty basic commandbutton that copies a range of data from my "import" sheet to a row in my "Main" sheet. What I am trying to now do is have the row on my "Main" sheet increase by 1 each time I click this button. So the first time I press this button the data will copy and paste to A10 on "Main", then next time i press the button it will paste to A11 on "Main" and so on, A12, A13, Etc... Whether this is even possible im not sure.

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


  Set copySheet = Worksheets("Import")
  Set pasteSheet = Worksheets("Main")


  copySheet.Range("E4:AA4").Copy
  pasteSheet.Range("A10").PasteSpecial xlPasteValues
  Application.CutCopyMode = False
  Application.ScreenUpdating = True


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi allstarsosa,

Welcome to MrExcel!!

Try this:

Code:
Option Explicit
Sub Macro1()
    
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False

    Set copySheet = Worksheets("Import")
    Set pasteSheet = Worksheets("Main")
    
    lngPasteRow = pasteSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
    If lngPasteRow < 10 Then
        lngPasteRow = 10
    End If

    copySheet.Range("E4:AA4").Copy
    pasteSheet.Range("A" & lngPasteRow).PasteSpecial xlPasteValues
    
    With Application
        .CutCopyMode = False
        .ScreenUpdating = True
    End With

End Sub

Regards,

Robert
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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