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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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
Wow! What a kind thing to say. However, I am not a "hero" either, just someone who is simply trying to help out when and where I am able to.

Those are the classic words of a hero (a modest hero).
 
Upvote 0

Forum statistics

Threads
1,215,618
Messages
6,125,870
Members
449,266
Latest member
davinroach

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