Copy Destination VBA Error

akjohno

New Member
Joined
Mar 27, 2018
Messages
27
Office Version
  1. 365
Platform
  1. Windows
I am copying the formulas from a range of cells and pasting them in the cells below for a range that is calculated from a CountA value as per the below code. The trouble is that the paste stops in random places and doesn't complete to the correct number of rows. This has had me scratching my head for over a week now but I still can't see where my mistake is. Can someone possibly enlighten me? The copy range is 22 cells that I need to paste down for example 30000 rows below, so the same formula copies down from row. My macro might cut out at row 7251 in one instance, then I run the macro again and it cuts out at 7885 or just in random spots like that, even though my CountA number is 30000. Please help? . Numshots is my CountA value....

VBA Code:
pastearea = "G5:AF" & NumShots + 3              'Assigns the variable pastearea the value of the cells we need to paste to
    Range("G4:AF4").Copy Destination:=ActiveSheet.Range(pastearea)  'Copies the formulas from cells G4 to AF4 to the entire range needed
    Do While Workbooks(wbname).Worksheets("Sheet1").Range("AF" & NumShots + 3) = ""
 
Ok, but at least we are getting the same Last orw
Have you tried clearing the clipboard after each run
VBA Code:
Application.CutCopyMode=False
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Ok, but at least we are getting the same Last orw
Have you tried clearing the clipboard after each run
VBA Code:
Application.CutCopyMode=False
tried that and it worked the first time doing the F8 step into, but when I run it as a macro I get the Run-time error '1004': Copy Method of Range Class Failed at the line
VBA Code:
Range("G4:AF4").Copy Destination:=ActiveSheet.Range(pastearea)  'Copies the formulas from cells G4 to AF4
 
Upvote 0
What happens if you just define pastearea as "G5" rather than "G5:AF" & NumShots + 3
 
Upvote 0
What happens if you just define pastearea as "G5" rather than "G5:AF" & NumShots + 3
Just tried this and it stopped at Q8039 instead of G29452. As in it pasted everything correctly up to row 8038 but stopped at column Q on the 8039th row:cry:
 
Upvote 0
Just for reference if you are using Destination then you only need to know the top left cell of the destination the same as you do in a paste or pastespecial.

Just tried this and it stopped at Q8039 instead of G29452. As in it paster everything correctly up to row 8038 but stopped at column Q on the 8039th row:cry:
Then test the value of numshots as you are using Counta to get the count of the rows which only counts cells with something in them and you will probably find that the value of numshots is not what you expect/need.
 
Upvote 0
Just for reference if you are using Destination then you only need to know the top left cell of the destination the same as you do in a paste or pastespecial.


Then test the value of numshots as you are using Counta to get the count of the rows which only counts cells with something in them and you will probably find that the value of numshots is not what you expect/need.
Nope, NumShots is definitely 29449. That’s what’s got me stumped?
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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