Jose said:
Hi,
I have 4 columns, 2 start date and 2 end dates. In most cases, both are the
same. In some, the start date is the same and the end date is different and
vice versa, how can I accurately get the number of days overlap?
Someone must have been wondering where I was. Try:
http://groups.google.com/group/comp.databases.ms-access/msg/9df7500e40e39155
It should work in an Excel Macro also. Something like (air code):
Dim Wks As Worksheet
Dim lngLastRow As Long
Dim lngI As Long
Set Wks = ActiveSheet
With Wks
lngLastRow = .Cells(.Rows.Count, "A".End(xlUp).Row
End With
For lngI = 2 To lngLastRow 'Headings on row 1
With wks
If Not IsEmpty(.Cells(lngI, "A").Value) And Not
IsEmpty(.Cells(lngI, "B").Value) And Not IsEmpty(.Cells(lngI,
"C").Value) And Not IsEmpty(.Cells(lngI, "D").Value) Then
If IsDate(.Cells(lngI, "A").Value) And IsDate(.Cells(lngI,
"B").Value) And IsDate(.Cells(lngI, "C").Value) And IsDate(.Cells(lngI,
"D").Value) Then
.Cells(lngI, "E").Value = DateIntersection(CDate(.Cells(lngI,
"A").Value), CDate(.Cells(lngI, "B").Value), CDate(.Cells(lngI,
"C").Value), CDate(.Cells(lngI, "D").Value))
End If
End If
End With
Next lngI
'You can put DateIntersection code here
Columns A through D should be formatted as dates. The macro will put
the number of days of overlap in column E. This example assumes that
columns A and B contain a start and end date and that columns C and D
contain another start and end date. You'll probably have to edit out
any carriage returns caused by line wrap.
James A. Fortune
(e-mail address removed)