Using column count to end of range

smartpat19

Board Regular
Joined
Sep 3, 2014
Messages
114
I have two dates and i am trying to create a dynamic date range based on those two dates.

in cell E5 is my starting date and E7 is my ending date. I have a formula to count the number of months between the dates in Y8="IFERROR(DATEDIF(E5,E7,"m"),0)"

I cannot get the end of range to copy my Edate formula. Or if there is a way to avoid using Y8's fromula that would be ideal.


Code:
Sub Update_Actuals()

Dim job As Worksheet
Dim column As Range
Dim columncount As Long




Set job = ThisWorkbook.Sheets("Job Cost Query")


job.Range("AF13").Formula = "=E5"


column = job.Range("Y8").Value


Set columncount = column + 14


Date = job.Range("AG13").Formula = "=EDATE(AF13,1)"
Date.Copy
Set daterange = job.Range(Cells(34.13), Cells(columncount, 13)).Paste


End Sub

Thank you ahead of time!
 
Try this

Code:
Sub Update_Actuals()
  Dim i As Long, lc As Long, lr As Long
  lc = Cells(13, Columns.Count).End(xlToLeft).Column  'last column
  lr = Range("AG" & Rows.Count).End(xlUp).Row         'last row
  If lc < Columns("AG").Column Then lc = Columns("AG").Column
  If lr < 13 Then lr = 13
  Range(Cells(13, "AG"), Cells(lr, lc)).ClearContents
  For i = 0 To DateDiff("m", Range("E5"), Range("E7"))
    Cells(13, Columns("AG").Column + i) = WorksheetFunction.EDate(Range("E5"), i)
    Range("Z31:Z78").Copy Cells(14, Columns("AG").Column + i)
  Next
[COLOR=#0000ff]  Range("AK7") = WorksheetFunction.Sum(Range("AG14").Resize(63, i))[/COLOR]
End Sub

This is great! Can we make it a formula in the cell? instead of the value?
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try

Code:
Range("AK7").Formula = "=sum(" & Range("AG14").Resize(48, i).Address & ")"
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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