Macro to autofill month end dates between start date and end date

AndreDo

New Member
Joined
Nov 4, 2019
Messages
7
Hi Guys,

I found a macro in this forum that list all the dates between end date and start date but I can't seem to figure out how to make it only display only month end dates! Can any excel ninja here help me with this?

Sub FillDates()
Dim StartD As Date, EndD As Date

StartD = Worksheets("Sheet1").Range("B1").Value
EndD = Worksheets("Sheet1").Range("B2").Value


For Row = 1 To EndD - StartD
Cells(Row, 1) = StartD + Row - 1


Next Row

End Sub

Thank you in advance,
Dre
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this

Code:
Sub FillDates()
  Dim StartD As Date, EndD As Date, i As Long, n As Long
  StartD = Worksheets("Sheet1").Range("B1").Value
  EndD = Worksheets("Sheet1").Range("B2").Value
  n = DateDiff("m", StartD, EndD)
  For i = 1 To n
    Cells(i, 1) = WorksheetFunction.EoMonth(StartD, i - 1)
  Next
End Sub
 
Upvote 0
It works, WHOA!!!!!!! I would have never thought of that. Thank you so much @DanteAmor. One small issue is this does not display the last month's date. If i enter startdate=9/2018 and enddate=12/2018 the output is: 9/30/2018,10/31/2018, and 11/30/2018
 
Upvote 0
It works, WHOA!!!!!!! I would have never thought of that. Thank you so much @DanteAmor. One small issue is this does not display the last month's date. If i enter startdate=9/2018 and enddate=12/2018 the output is: 9/30/2018,10/31/2018, and 11/30/2018

Try this

Change this line:
Code:
For i = 1 To n


For this
Code:
For i = 1 To n[COLOR=#0000ff] + 1[/COLOR]
 
Upvote 0
I don't know if you will find this interesting, but here is a non-looping macro that can also be considered...
Code:
Sub FillDates()
  Dim Arr As Variant
  Arr = Evaluate("IF({1},EOMONTH(B1,ROW(1:" & 1 + DateDiff("m", [B1], [B2]) & ")-1))")
  With Range("A1").Resize(UBound(Arr))
    .NumberFormat = "m/d/yyyy"
    .Value = Arr
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,665
Members
452,992
Latest member
TokugawaIesuma

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