Copy data from the last row from a sheet to another sheet using a macro in an excel report
This simple code is just to copy a data from a sheet and to paste them in another sheet but before that, it will find the last row with value so it will paste the data to the next row, the empty one.
When I use the macro ?
To copy a data from a sheet then to paste it to another sheet from the first empty cell.
How to create the macro ?
Read How to create, edit, hide and select a macro in an excel report
How to create the button to associate it with the macro ?
Read How to create a button and associated it to a macro in an excel report
How is/are the macro(s) ?
Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need. This one should be run from Sheet1 (the sheet where to paste):
Sub test() Dim LastRow As Long ' change Sheet1 by your sheet name where to paste LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row ' change Sheet2 by your sheet name where to copy and Sheet1 by the same name to paste ' change A2:D5 by your cell reference to copy Sheets("Sheet2").Range("A2:D5").Copy Sheets("Sheet1").Cells(LastRow, 1) End Sub
This one should be run from Sheet2 (the sheet where to copy):
Sub test() Dim LastRow As Long Dim rng As Range ' change Sheet1 by your sheet name where to paste LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row Set rng = ActiveSheet.UsedRange Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1) rng.Select rng.Copy Sheets("Sheet1").Cells(LastRow, 1) End Sub
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...