Dynamic Selection.Autofill using variable

flaaron

New Member
Joined
Jul 5, 2011
Messages
5
Currently I have a value in a column that I am extending by a fixed number using relative references.

Selection.AutoFill Destination:=ActiveCell.Range("A1:A34"), Type:=xlFillCopy

This makes the autofill inflexible because the relative reference range ("A1:A34") is fixed. Usually the number of records is the same, so no big deal, but whenever the number of records increases or decreases, the autofill should expand or contract to fit. Right now I have to manually that statement.

When importing my sheet I count the number of records (columns) and keep it in a variable "TimeRowOffset". Is there a way to use this variable in the range? Ideally I could just use the following:

Selection.AutoFill Destination:=ActiveCell.Range("A1:TimeRowOffset"), Type:xlFillCopy

When I run that I get a compile error saying "Expected: named parameter"

Any help would be much appreciated!

~Aaron
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Is TimeRowOffset the number of rows or columns?

If rows, you can modify your code to
Rich (BB code):
Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & TimeRowOffset), Type:xlFillCopy
 
Upvote 0
Try

Code:
Selection.AutoFill Destination:=Range("A1:A" & TimeRowOffset), Type:=xlFillCopy
 
Upvote 0
Couldn't you just use Copy?
Code:
ActiveCell.Copy ActiveCell.Resize(TimeRowOffset)
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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