Select Lastrow + 2 "NEWBIE"

wrightyrx7

Well-known Member
Joined
Sep 15, 2011
Messages
994
Hi all,

I have tried to record a macro to give me an idea of how the VBA code will go. I am trying to create a macro that will do the following:-

Copy data from a worksheet but as the number of rows changes every month it needs to be as follows.

Column H(lastrow +2) & Column I(lastrow +2)

then i want it to paste on my Summary worksheet. Here is the code from the recorded macro. As you can see with the first one i have tried changin it but it doesnt seem to work.

Sub Macro6()


Sheets("GMPF Added Years").Select
Range(LASTROW + 2, "H").Select
Selection.Copy
Sheets("Summary").Select
Range("B4").Select
ActiveSheet.Paste

Sheets("GMPF Added Years").Select
Range("I11").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("C4").Select
ActiveSheet.Paste

Sheets("GMPF Add Reg Cont").Select
Range("H4").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("B5").Select
ActiveSheet.Paste

Sheets("GMPF Add Reg Cont").Select
Range("I4").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("C5").Select
ActiveSheet.Paste

Sheets("GMPF").Select
Range("H1286").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("B6").Select
ActiveSheet.Paste

Sheets("GMPF").Select
Range("I1286").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("C6").Select
ActiveSheet.Paste

Sheets("GMPV AVC").Select
Range("H9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
ActiveSheet.Paste

Sheets("GMPV AVC").Select
Range("I9").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Summary").Select
Range("C9").Select
ActiveSheet.Paste

Any help would be great

Thanks
Chris
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What's lastrow? If it's the row number of the last nonblank cell why do you want to copy the blank cell 2 rows below it?
 
Upvote 0
Hello thank you for the reply,

Yes last row is the row number of the last nonblank. I want 2 rows below because a macro i run first totals the column and puts the result in Lastrow + 2.

Thats the data i want to copy.

Thanks
Chris
 
Upvote 0
So it's LastRow at that stage. Instead of:

Code:
Sheets("GMPF Added Years").Select
Range(LASTROW + 2, "H").Select
Selection.Copy
Sheets("Summary").Select
Range("B4").Select
ActiveSheet.Paste

try:

Code:
Dim LastRow As Long
With Sheets("GMPF Added Years")
    LastRow = .Range("H" & .Rows.Count).End(xlUp).Row
    .Range("H" & LastRow).Copy Sheets("Summary").Range("B4")
End With

Note that generally it's not necessary to select an object to use its properties/methods.
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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