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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,216,458
Messages
6,130,757
Members
449,588
Latest member
accountant606

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