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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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