Autofill within a For Loop

adampnt

New Member
Joined
Jun 22, 2011
Messages
2
I've got some code within a For loop that works fine until I try to use autofill at the end of each iteration. Here is my code:

For y = 1 To 100
...
whole bunch of working code
...

Sheets("QuickTest").Activate
ActiveSheet.Range(Cells(y + 1784, 2), Cells(y + 1784, 101)).Select
Selection.AutoFill Destination:=Range(Cells(y + 1785, 2), Cells(y + 1785, 101)), Type:=xlFillDefault

Next

The error is raised on the final line (Selection.Autofill . . . )

Any ideas here would be greatly appreciated. Thanks so much for your help.

-Adam
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Adam

Welcome to the forum

fyi - Extract from the Help on Range.Autofill -

<TABLE><TBODY><TR><TD class=mainsection>Destination</TD><TD class=mainsection>Required</TD><TD class=mainsection>Range</TD><TD class=mainsection>The cells to be filled. The destination must include the source range.</TD></TR></TBODY></TABLE>

So your code becomes -

Code:
ActiveSheet.Range(Cells(y + 1784, 2), Cells(y + 1785, 101)).Select
Selection.Resize(1,100).AutoFill Destination:=Selection, Type:=xlFillDefault

hth
 
Upvote 0
Thanks a ton, Mike. I'd been stuck on that for a while, and your fix worked like a charm.

Cheers,

Adam
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

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