Selection.autofill for all data in two rows

chrislehr

New Member
Joined
Sep 10, 2014
Messages
1
Hey all,

Long time reader, first time registering and posting. Two questions on some code I am working on:

I have code where I am trying to automate some processing some CSV data. In one section, I am adding two lines, one for =average() and one for =max() for the range of the columns. There use:
ActiveCell.FormulaR1C1 = "=AVERAGE(R[2]C:R[15000]C)"

To select the data. Obviously, 15000 is an arbitrary hard coding. I'd prefer to have it select til the last row for this.

The next thing it does is copy the formulas from those two cells (B2 and B3) and copy the formula across ALL columns.

For this I am currently using:
Selection.AutoFill Destination:=Range("B2:ARD3"), Type:=xlFillDefault

Again, ARD is arbitrary, that just happens to be the longest example in my sample data. How can I make this instead select the last column with data in it?

I also tried this, not sure if it's incorrect or not:
Selection.AutoFill Destination:=Range("B2", Range("B3").End(xlToRight)).Select, Type:=xlFillDefault

A lot of the examples I have found googling this are for a single line (so select B2 and copy to end, but not b2 and b3 to end)

Maybe it would be easier programmatically to do one line at a time?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,222,038
Messages
6,163,549
Members
451,843
Latest member
vitto

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