VBA for Copy and paste to last row

cufflink23

New Member
Joined
Dec 15, 2011
Messages
4
I want to copy and paste G2:M2 to the last row in that range. How do i write the code to paste the selection to the last row, defined by column A.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to the board.

Code:
Sub Copy()
Dim Last_Row As Long

Last_Row = Range("G2").End(xlDown).Offset(1).Row

Range("G2:M2").Copy Range("G" & Last_Row)

End Sub
 
Upvote 0
OK, so that is not working. let me give you some more detail.

Columns A-F will stay the same, the data will just get longer (each week/month). So i am writing formulas in columns G thru M, but want to copy those forumlas to the end of the data (defined by column A). That is the part I want to automate with the macro.
 
Upvote 0
Change
Code:
Last_Row = Range("G2").End(xlDown).Offset(1).Row
to
Code:
Last_Row = Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0
Reading your original post, I assumed you wanted the formulae pasted to the last row. The below code will paste to the entire range...

Code:
Sub Copy()
Dim Last_Row As Long
Last_Row = Range("A" & Rows.Count).End(xlUp).Row
Range("G2:M2").Copy Range("G3:M" & Last_Row)
End Sub
 
Upvote 1
An altnernative to njimack's suggestion is:
Code:
Sub CopyFormulae()

Dim i as Long

Application.ScreenUpdating = False

i = Range("A" & Rows.Count).End(xlUP).Row
Range("G2:M" & i).FillDown

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Hi guys,
I'm posting here 'cause the problem is similar to the one already solved, however, I still need some help. I have a table with 6 rows and a few columns. I want to add a "+" button in order to paste a copy of the last row in use. To be more specific, if I press +, I need to insert a copy of row 6 (A6:E6), to row 7 (A7:E7). I need to use the button every time i want to add one more row, so I must always know which one's the last row in use, and where to paste a copy of the row. It's very important to be copy & paste.
Thanls!
 
Upvote 0
You give a solution to fill the same datas till the last row.
How NOT FILL but just COPY AND PASTE a ROW aftrer the last row of a table?
Thanks Ivan
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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