Autofill Help

tcnt9176

Board Regular
Joined
Jun 23, 2008
Messages
223
I hope there is a quick alteration to this script below. This is generally the script I use whenever I need to autofill a column in a spreadsheet. How do I alter this in a case where the cell I want to autofill changes (dyanamic). Until now, it has always started in the 2nd row but this time it could change. I tried defining "FirstRow" by active cell without any luck. Thanks for your help.

Code:
    Range("O2").Select
    LastRow = Range("A65536").End(xlUp).Row
    Selection.AutoFill Destination:=Range("O2:O" & LastRow)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi tcnt9176,

You can use the fact that the Range property can accept two arguments (defining the beginning and end of the range) combined with the Cells property, like this:

Selection.AutoFill Destination:=Range(Cells(FirstRow,"O"),Cells(LastRow,"O"))

Of course, the value of the FirstRow variable will have to have been previously assigned.

Keep Excelling.

Damon
 
Upvote 0
I got Run-time error '13': Type mismatch. Is that because I need to define FirstRow?How would I define First Row as ActiveCell?
I tried this but it stopped on the line you gave me.

Code:
    FirstRow = ActiveCell
    LastRow = Range("A65536").End(xlUp).Row
    Selection.AutoFill Destination:=Range(Cells(FirstRow, "O"), Cells(LastRow, "O"))
 
Upvote 0
Hi again tcnt9176,

FirstRow is an integer row number, while ActiveCell is a Range Object. To get the active cell's row you can do it like this:

FirstRow = ActiveCell.Row


Damon
 
Upvote 0

Forum statistics

Threads
1,216,533
Messages
6,131,216
Members
449,636
Latest member
ajdebm

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