View Single Post
  #4   Report Post  
Richard Buttrey
 
Posts: n/a
Default

On Mon, 5 Sep 2005 10:26:29 +0100, "MissSara"
wrote:

Hello, I need a function which allows me to enter the start and end dates
for two date-periods, then returns 'True' if there is any crossover
(intersection) between the two periods. In simple terms if there is any day
(or days) which appears in both periods.

Can I do this with worksheet functions? or do I need VBA? Very grateful for
any tips on how I code it.

Sara



In VBA one solution is a simple looping procedure e.g. below

This assumes A1 is named "Date1"
A2 is named "Date2"
A1 is the start date of the first period
B1 is the end date of the first period
A2 is the start date of the second period
B2 is the end date of the second period
A4 contains the text "Overlap Dates"

All dates are standard Excel date 'numbers'


Sub Overlapdates()
Dim date1 As Date, x As Double, y As Double
Dim date2 As Date

x = Range("date2").Cells(1, 2) - Range("date2").Cells(1, 1)

For y = 0 To x
If Range("date2") + y = Range("date1") And _
Range("date2") + y <= Range("date1").Cells(1, 2) Then
Range("a65536").End(xlUp).Offset(1, 0) = Range("date2") + y
End If
Next

End Sub

HTH



__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________