Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default comparing a date range within another date range

Hi,

What I'm trying to do is create a program that loops through a small set of
dates that I have in column D and E (start dates and end dates). So, it
takes these line by line and compares them to another larger set of dates in
column A and B. The result is to show if any of the dates from Column D and
E fall in between the dates of column A and B. Furthermore, each group of
dates has a unique number id. So, the data consists of dates that are
grouped by number IDs.
Example:

Group 1 Group 2
id start_date end_date id start_date end_date
-----------------------------
----------------------------------
1 6-6-07 6-7-07 1 6-6-07 6-10-07
1 6-9-07 6-11-07 2 etc etc
1 6-13-07 6-15-07 3 etc etc
2 etc etc
3 etc etc

So I need a way to take group 2's date values and compare to see if they
fall between the correct group id for Group 1's dates. Any ideas would be
great. Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default comparing a date range within another date range

You need to show either Group 2 start date or end date falls within one of
the Group 1 ranges. You can have any one of the following conditions

1) Group 2 dates falls outside Group 1 dates
2) Group 2 dates fall inside the Group 1 dates
3) Group 2 date starts before Group 2 date but ends in the midde of Group 2
dates
4) Group 2 date starts in the middle of Group 1 dates but ends after Group 1
5) Group 1 dates start before Group 2 dates and end after Group 2 dates


Sub checkdates()


LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set Group1Range = Range(Cells(1, "A"), Cells(LastRow, "A"))

LastRow = Cells(Rows.Count, "D").End(xlUp).Row
Set Group2Range = Range(Cells(1, "D"), Cells(LastRow, "D"))


For Each Group2cell In Group2Range

If IsDate(Group2cell) Then

For Each Group1cell In Group1Range

If IsDate(Group1cell) Then

If (((Group2cell = Group1cell) And _
(Group2cell <= Cells(Group1cell.Row, "B"))) Or _
((Cells(Group2cell.Row, "E") = Group1cell) And _
(Cells(Group2cell.Row, "E") <= Cells(Group1cell.Row, "B"))))
Or _
((Group2cell <= Group1cell) And _
(Cells(Group2cell.Row, "E") = Cells(Group1cell.Row, "B")))
Then

'enter your code when both conditions are met


End If

End If

Next Group1cell

End If

Next Group2cell

End Sub


"prog" wrote:

Hi,

What I'm trying to do is create a program that loops through a small set of
dates that I have in column D and E (start dates and end dates). So, it
takes these line by line and compares them to another larger set of dates in
column A and B. The result is to show if any of the dates from Column D and
E fall in between the dates of column A and B. Furthermore, each group of
dates has a unique number id. So, the data consists of dates that are
grouped by number IDs.
Example:

Group 1 Group 2
id start_date end_date id start_date end_date
-----------------------------
----------------------------------
1 6-6-07 6-7-07 1 6-6-07 6-10-07
1 6-9-07 6-11-07 2 etc etc
1 6-13-07 6-15-07 3 etc etc
2 etc etc
3 etc etc

So I need a way to take group 2's date values and compare to see if they
fall between the correct group id for Group 1's dates. Any ideas would be
great. Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing a date with a range of dates Hany ElKady Excel Worksheet Functions 5 June 8th 09 05:47 PM
Create a formula in a date range to locate a specific date - ecel util Excel Discussion (Misc queries) 0 February 19th 07 03:03 PM
copy date based on date -refer to date range mindpeace[_4_] Excel Programming 1 June 3rd 06 01:30 PM
Formula for determining if two date columns fall within specific date range Igottabeme Excel Worksheet Functions 2 April 21st 06 02:50 AM
How to count dates within a certain range in a column with mutiple date range entries Krisjhn Excel Worksheet Functions 2 September 1st 05 01:59 PM


All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"