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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,215,593
Messages
6,125,715
Members
449,254
Latest member
Eva146

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