How to get list of in-between dates in dd-mmm-yyyy fromDate and ToDate

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Hello

How can i list down the in-between dates in (dd-mmm-yyyy) format from below textboxes ie txtFromDate.text and txtToDate.Text
also the list to contain the dates txtFromDate.Text and txtToDate.text with in-between dates

Code:
Option Explicit
Dim fromDate As Date, toDate As Date

Private Sub txtFromDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If txtFromDate.Value = vbNullString Then
    Exit Sub
ElseIf Not IsDate(txtFromDate.Value) Then
    Cancel = True
    MsgBox "Invalid date, please re-enter", vbCritical


    txtFromDate.Value = vbNullString
    txtFromDate.SetFocus
    'MsgBox "Invalid date, please re-enter", vbCritical
    Exit Sub
End If
fromDate = DateSerial(Year(Date), Month(Date), Day(Date))
txtFromDate.Value = Format(CDate(txtFromDate.Value), "dd-mmm-yyyy")

End Sub

Private Sub txtToDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If txtToDate.Value = vbNullString Then
    Exit Sub
ElseIf Not IsDate(txtToDate.Value) Then
    Cancel = True
    MsgBox "Invalid date, please re-enter", vbCritical


    txtToDate.Value = vbNullString
    txtToDate.SetFocus
    'MsgBox "Invalid date, please re-enter", vbCritical
    Exit Sub
End If
toDate = DateSerial(Year(Date), Month(Date), Day(Date))
txtToDate.Value = Format(CDate(txtToDate.Value), "dd-mmm-yyyy")

End Sub
Thanks NimishK
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello,

An Array Formula could do the job for you ...

With you Start Date in cell A2 and your End Date in cell A3 ...

In cell B2, you could test following:

Code:
=IFERROR(SMALL(IF(ISNA(MATCH(ROW(INDIRECT(MIN($A$2:$A$3)&":"&MAX($A$2:$A$3))),$A$2:$A$3,0)),ROW(INDIRECT(MIN($A$2:$A$3)&":"&MAX($A$2:$A$3)))),ROWS($1:1)),"")

Then you can copy formula down ... to get your list

Hope this will help
 
Upvote 0
you can try PowerQuery (Get&Transform)

FromDateToDateDays
01/01/2019​
10/02/2019​
01/01/2019​
02/01/2019​
03/01/2019​
04/01/2019​
05/01/2019​
06/01/2019​
07/01/2019​
08/01/2019​
09/01/2019​
10/01/2019​
11/01/2019​
12/01/2019​
13/01/2019​
14/01/2019​
15/01/2019​
16/01/2019​
17/01/2019​
18/01/2019​
19/01/2019​
20/01/2019​
21/01/2019​
22/01/2019​
23/01/2019​
24/01/2019​
25/01/2019​
26/01/2019​
27/01/2019​
28/01/2019​
29/01/2019​
30/01/2019​
31/01/2019​
01/02/2019​
02/02/2019​
03/02/2019​
04/02/2019​
05/02/2019​
06/02/2019​
07/02/2019​
08/02/2019​
09/02/2019​
10/02/2019​

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Inserted Time Subtraction" = Table.AddColumn(Source, "Subtraction", each [ToDate] - [FromDate], type duration),
    #"Calculated Total Days" = Table.TransformColumns(#"Inserted Time Subtraction",{{"Subtraction", Duration.TotalDays, type number}}),
    #"Added Custom" = Table.AddColumn(#"Calculated Total Days", "Days", each List.DateTimes([FromDate],[Subtraction]+1,#duration(1,0,0,0))),
    #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Days"),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded Days",{"Days"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Days", type date}})
in
    #"Changed Type"[/SIZE]
 
Upvote 0
Guys thanks for your inputs.
James006 for your below code require VBA syntax
Code:
=IFERROR(SMALL(IF(ISNA(MATCH(ROW(INDIRECT(MIN($A$2:$A$3)&":"&MAX($A$2:$A$3))),$A$2:$A$3,0)),ROW(INDIRECT(MIN($A$2:$A$3)&":"&MAX($A$2:$A$3)))),ROWS($1:1)),"")


Sandy666
Power Query have really not worked. And wanted the help in simple VBA. if you have solved the same without power query or before power query was launched would really appreciate
 
Upvote 0
I left vba in favor of power query so I can't help you

have a nice day
 
Upvote 0
Hello,

The VBA equivalent can be easily achieved ...

Just turn on your macro recorder and input the formula ...

HTH
 
Upvote 0
Hi, here is an alternative you could try - this lists the dates starting in cell A1 of the active sheet downwards and is attached to command button 1.

Code:
Private Sub CommandButton1_Click()
Dim i As Long
i = DateValue(txtToDate) - DateValue(txtFromDate)
With Range("A1").Resize(i + 1)
    .Value = Evaluate("datevalue(""" & txtFromDate & """) + (row(1:" & i + 1 & ")-1)")
    .NumberFormat = "dd-mmm-yyyy"
End With
End Sub
 
Upvote 0
FormR
Excellent One. You have Formed exactly to what i wanted. Just The perfect one.(y)
Something new i.e Evaluate i've learnt Today.

James006 will also add into Macro Recorder to turn on the Formula. Not yet tried. Thanks
Sandy666 No isssues but will surely keep in mind your formula when i wiill work on Power Query. Thanks Anyways

Thanks Guys
NimishK
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,203
Messages
6,123,627
Members
449,109
Latest member
Sebas8956

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