+ Reply to Thread
Results 1 to 4 of 4

Macro not identifying all overlaps between dates

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Macro not identifying all overlaps between dates

    Challenge is to identify all the "overlaps" between the policies in Col E taken out against the same loan in Col B.

    Attached Macro works perfectly where there is an overlap between consecutive rows, but I can't work out how to make it "see" the overlaps that may be on a non-consecutive row, and map that overlap.

    E.g. Rows 10 - 12 show loan 193672 has been covered by Policies 9, 10 and 11. The Macro identifies the overlap between Policies 9 and 10, and between 10 and 11, but "misses" that there is still an overlap between Policies 9 and 11 after Policy 10 expires.

    Option Explicit
    
    Sub OVERLAPS()
    
    Dim f As Long, n As Long
    
    f = Cells(Rows.Count, 2).End(xlUp).Row
    
    For n = 3 To f
    
    'Check for overlaps
        If Range("B" & n) = Range("B" & n - 1) Then
            If Range("F" & n) < Range("G" & n - 1) Then
                If Range("G" & n) < Range("G" & n - 1) Then
                Range("H" & n) = Range("F" & n) & "- " & Range("G" & n)
                Else: Range("H" & n) = Range("F" & n) & "- " & Range("G" & n - 1)
                End If
            End If
        End If
        
        Next
        
    End Sub
    Cols M - AB demonstrate the overlaps that should be captured.

    Hope it's clear, and all suggestions, pointers and solutions welcome as ever.

    Ochimus
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Macro not identifying all overlaps between dates

    This seems doable with a formula? If I'm understanding the objective correctly, try array-entering the formula below in H2 and filling down:

    =IF(SUMPRODUCT(($B$1:$B1=$B2)*($G$1:$G1>=$F2)*($F$1:$F1<=$G2))>0,TEXT($F2,"DD/MM/YY")&" - "&TEXT(MIN($G2,LARGE(IF(($B$1:$B1=$B2)*($G$1:$G1>=$F2)*($F$1:$F1<=$G2)=1,$G$1:$G1),1)),"DD/MM/YY"),"")

    I believe that it will return the range of overlap dates when they occur. Try testing the attachment to see if I've got it right:
    Attached Files Attached Files
    If your problem has been solved, please use "Thread Tools" to mark the thread as "Solved".

    If you're grateful for this site's existence and would like to contribute to the community, please consider posting something hilarious in our joke thread:
    https://www.excelforum.com/the-water...ke-thread.html

  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Re: Macro not identifying all overlaps between dates

    CAntosh,

    Spot On!

    Does exactly what it needs to on the sample. Will try shuffling dates around, and adding something with five rows and four links, but can't see it not working.

    Happy to mark this as "Solved"

    Ochimus

  4. #4
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Macro not identifying all overlaps between dates

    Glad to help, good luck!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Identifying End of Month dates across years of daily dates
    By bigdolph in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-01-2016, 04:42 PM
  2. How to change dates if the date overlaps
    By redza in forum Excel General
    Replies: 3
    Last Post: 09-30-2013, 12:37 AM
  3. [SOLVED] Identifying dates that are not included
    By leslieharris in forum Excel General
    Replies: 7
    Last Post: 08-14-2012, 08:17 AM
  4. Identifying Similar Dates
    By wawa in forum Excel General
    Replies: 5
    Last Post: 05-09-2012, 04:56 PM
  5. Identifying weekend dates in a list of dd/mm/yy dates
    By Gooford in forum Excel General
    Replies: 4
    Last Post: 01-07-2010, 10:01 AM
  6. identifying dates for this week and next
    By martinz in forum Excel General
    Replies: 7
    Last Post: 10-11-2009, 12:07 AM
  7. [SOLVED] Identifying Date Overlaps
    By Tremain in forum Excel General
    Replies: 1
    Last Post: 05-09-2005, 09:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1