Autofill for dynamic range

Trevasaurus

New Member
Joined
Dec 4, 2012
Messages
13
Hi. My problem seems simple but I'm having a lot of difficulty getting my Macro to work properly.

I have a sheet with a Column (A) of Dates and a Row (1) of Column Headers. Count of dates and Column headers change every day. I'm placing a lookup formula in B2 and I'd like it to do two things:
1. Auto fill down as far as the count of Column A (Range B:#)
2. Auto fill the new range in Column B2:#, to the right, as far as the Column Headers in Row 1.

This is what I have so far. It fills the code down to last row, but not to the right to last column.

Code:
Sub Auto_Fill()

With Sheets("Sheet1").Range("B2")
    .Formula = "=HLOOKUP($A2,Sheet2!$V$9:$XFD$120000,MATCH(B$1,Sheet2!$F$11:$F$3000,0)+2,FALSE)"
    .Resize(Cells(Rows.Count, "A").End(xlUp).Row - 1, 1).FillDown<code>
  .Resize(Cells(1, Columns.Count).End(xlToLeft).Column - 1).FillRight</code>
End With

End Sub

Any help is greatly appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try adding a comma (in red below):
Rich (BB code):
With Sheets("Sheet4").Range("B2")
    .Formula = "=HLOOKUP($A2,Sheet2!$V$9:$XFD$120000,MATCH(B$1,Sheet2!$F$11:$F$3000,0)+2,FALSE)"
    .Resize(Cells(Rows.Count, "A").End(xlUp).Row - 1, 1).FillDown
  .Resize(, Cells(1, Columns.Count).End(xlToLeft).Column - 1).FillRight
End With
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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