Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Simple Copying one Range to Another Range

Tags:

vba

excel-2011

This is a really simple VBA formula but it's failing. It's only pasting into cell A6 onwards. Is it just me? Excel 2011 by the way.

Range("A4:A5").Select
Selection.Copy
Range("A6:A1000").Select
ActiveSheet.Paste
like image 341
SparrwHawk Avatar asked Sep 21 '11 18:09

SparrwHawk


1 Answers

I think the issue is that you have two different values in A4 and A5 and so excel can only repeat those values in the paste range if the paste range is an even number of cells.

This works for me:

Range("A4:A5").Copy Destination:=Range("A6:A1001")

Note that A6:1001 is 996 cells (an even number). Using A6:A1000 is 995 and is an odd number so excel cannot work out how to repeat your values from A4 to A5.

I think this is the issue...but happy to be educated otherwise...

like image 172
Alex P Avatar answered Oct 04 '22 10:10

Alex P