Copy and paste issue

Craig1

Active Member
Joined
Jun 11, 2009
Messages
322
Hi All,
I use some code (courtesy of the forum) but it has one little glitch in that I would like to repair if possible.

The code copies a couple of functions in some cells and pastes them into columns K & L where the new info has just been inputted.
The issue is that if I pull across from rows 15 thru to 30 it inputs the functions into rows 14 thru to 30. It just seems to be that one row up each time. I have tried ammending the code but no luck so far.
The code is:-

Dim LASTROW As Long
Dim lastrow2 As Long

LASTROW = Cells(Rows.Count, 1).End(xlUp).Row
lastrow2 = Cells(Rows.Count, 11).End(xlUp).Row
Range("K1:L1").Copy
Range("K" & lastrow2 & ":L" & LASTROW).Select
Selection.PasteSpecial Paste:=xlPasteFormulas

Any help would be appreciated.

Craig.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello Craig1,

I would check that both Lastrow and Lastrow2 have the same value.

Sincerely,
Leith Ross
 
Upvote 0
Leith, thanks for the quick reply. Not sure what you mean "same value".
I have just tried changing them both to the same last row and one inserted the functions a row above my data and the 2nd trial inputted the functions at the bottom of my data on the last row.

Craig.
 
Upvote 0
Hello Craig1,

I am little mystified by why you are finding the ends of both rows. Shouldn't they end at the same row? Is your starting row always 15 or does it change?

Sincerely,
Leith Ross
 
Upvote 0
Leith, it changes all the time. It all depends how many rows I copy across from another workbook. Sometimes it may be 15 rows or it could be 150 rows. The code always does what I want except it also copies the functions from K1 & L1 into the row above.

Craig.
 
Upvote 0
the elngh of your last rows are dependent on the column number so Lastrow is counting how many rows have info in A:A try changeing the 1 to 12 where it says (rows.count, 1)
 
Upvote 0
Thanks for the reply Dryver14.
When I changed to your suggestion it only inserted the functions into the above my data.

Craig
 
Upvote 0
Dryver14,
This is why I need to stop it because it is causing problem in the row above when the auto filter is on (usually all the time) and the panes are frozen at this point.

Craig.
 
Upvote 0
ah ha

think I know what you are getting at now

at the end of the lines for lastrow = and lastrow2 =

put +1 after the .Row
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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