VBA Autofill horizontally referencing a variable date in a cell

armchairandy

Board Regular
Joined
Mar 27, 2012
Messages
53
I have the below vba to autofill the formula between J17 to ACP17 based on if there is data in column E.

Range("J17:ACP17").AutoFill destination:=Range("J17:ACP" & Range("E" & Rows.Count).End(xlUp).Row)

Works fine, but

J17 to ACP17 hold formulas that relates to a row of sequential dates, which is variable as the length of time constantly changes.

The problem I have is that from J17 to ACP17 there is a lot of unnecessary formulas making the workbook too large (multiple tabs using the same process).

Column E is ok, the data is copied in each time so the formulas downwards works fine.

What I would like to do is have a start date in J16, then autofill to the right up to the end date held in cell B1, then replace the J17:ACP17 section of the above formula with the last date in row 16.

Makes sense?

Any help would be appreciated

Regards

Andrew
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
Try this

VBA Code:
Sub test()
  Dim nDate As Long, j As Long
  
  j = 9
  For nDate = [J16] To [B1]
    j = j + 1
    Cells(16, j) = nDate
  Next
    
  Range("J17", Cells(17, j)).AutoFill Range("J17", Cells(Range("E" & Rows.Count).End(xlUp).Row, j))
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,619
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,596
Messages
5,625,716
Members
416,130
Latest member
galgozzi

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
Top