Autofill Down in VBA

coolkidz33

New Member
Joined
Feb 22, 2011
Messages
14
I really don't understand why Excel is so complicated when you autofill down in picking the correct range. Even if I record a macro and use Relative cell references, it still hard codes a range into the command. I have a formula in cell P2 that I want autofill to the bottom of the table. I recorded the macro below using Relative References thinking it would work. It does when there are only 13 rows. However, sometimes there are more than 13 rows. I am sure there is an easy macro to do this to the bottom of the column. Can anyone help with this? I would appreciate it. Jon




Range("P2").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A13")
ActiveCell.Range("A1:A13").Select
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try...
Code:
Sub Pfill()
Range("P2").AutoFill Range("P2:P" & Range("A" & Rows.Count).End(xlUp).Row)
End Sub
 
Upvote 0
Wow that was simple. Thank you so much. No matter how much I try to learn about VBA, these little things trip me up.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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