How many time particular date is coming between the set of two dates
Hi All,
I need to calculate, how many time particular date is coming between the set of two dates.
Please find the attached excel sheet for the format.
Kindly help me to create macro for this.
Attachment | Size |
---|---|
Question.xlsx | 14.28 KB |
Here you go - this should do it
Sub Datechecker()
Application.ScreenUpdating = False
Dim sdate, edate, pdate As Date
'find last entry in column A
s = Range("A19999").End(xlUp).Row
'find last entry in column F
F = Range("f19999").End(xlUp).Row
For x = 2 To F ' main loop for number of particular dates
times = 0
'get particular date
pdate = Cells(x, 6)
For y = 2 To s ' loop through start and end dates
sdate = Cells(y, 2)
edate = Cells(y, 3)
If pdate < sdate Then GoTo nexty ' too early
If pdate > edate Then GoTo nexty ' too late
'valid if here so increase nr of times
times = times + 1
nexty: Next y
'put times into column G
Cells(x, 7) = times
Next x
End Sub