Problem with VBA to Copy and Paste Rows

Match12

New Member
Joined
Apr 1, 2019
Messages
19
Office Version
  1. 2016
  2. 2010
I use this very simple code to copy and paste rows - that include merged cells, conditional formatting and some dropdowns.

VBA Code:
Sub Copy_rows()
 
  Range("A11:P11”).Copy
  Range("A12:P5000").Select
  ActiveSheet.Paste

End Sub
The idea is to copy everthing in Row 1 from A11:P11 into row 12 to 5000
Sometimes is works perfectly..other times it only copies down so far and then seem to fail to merge the cells. There is no consistency as to where it fails...other than roughly rows 1200 to 1350!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this. Maybe it would be more consistent:
VBA Code:
Range("A12:P5000").Value = Range("A11:P11").Value
 
Upvote 0
Try this. Maybe it would be more consistent:
VBA Code:
Range("A12:P5000").Value = Range("A11:P11").Value
That did not seem to do anything?


VBA Code:
Sub Copy_rows()

Range("A12:P5000").Value = Range("A11:P11").Value
End Sub
 
Upvote 0
That did not seem to do anything?


VBA Code:
Sub Copy_rows()

Range("A12:P5000").Value = Range("A11:P11").Value
End Sub
Maybe you should specify sheet names before ranges. That worked for me on the same sheet.
 

Attachments

  • 1677594741479.png
    1677594741479.png
    9.8 KB · Views: 2
  • 1677594775392.png
    1677594775392.png
    53.8 KB · Views: 2
Upvote 0
Did your test include Merged cells, borders, conditional formatting?
My problem seems to be the borders and merged cells more than anything else
 
Upvote 0
Could you please share what the formatting looks like without values?
 
Upvote 0
Starting in the column after "Model" those cells are merged, ,have borders, and contain Conditional Formatting.
One thing furhter investigation determined, the code always stops at row 1215!
 

Attachments

  • Capture.PNG
    Capture.PNG
    12.7 KB · Views: 5
Upvote 0
Strange.. Try to clear everything before pasting. I have no idea other than this.
VBA Code:
Sub Copy_rows()
 
  Range("A11:P11”).Copy
  Range("A12:P5000").Clear
  Range("A12:P5000").PasteSpecial Operation:=xlPasteAll

End Sub
EDIT: Somehow, it doesn't work. I hope this will work:

VBA Code:
Range("A11:P11").Copy
 
  Range("A12").Resize(4089, 16).PasteSpecial
 
Last edited by a moderator:
Upvote 0
I am wondering, as it only goes to row 1215, if it is some type of memory issue...
 
Upvote 0
I give up...will manually copy and paste!
Thank you for your suggestions! I am convinced it is a memory issue!
 
Upvote 0

Forum statistics

Threads
1,215,346
Messages
6,124,417
Members
449,157
Latest member
mytux

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