Within a date range

miyengar

Board Regular
Joined
Jun 22, 2012
Messages
54
Hello,
I want to find out in a range of dates which dates are within 5 days of each other.
Thanks for your help.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Thanks,
But this just compares 2 cells, right?
I'm looking for each cell to be compared to all others in a range.
 
Upvote 0
Definitely! Idea is to find dates that are within 5 days of each other.
 
Last edited:
Upvote 0
Try this for dates in column "A" starting "A2"
Code:
[COLOR="Navy"]Sub[/COLOR] MG13Feb28
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, L1 [COLOR="Navy"]As[/COLOR] Range, L2 [COLOR="Navy"]As[/COLOR] Range, nStr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] nn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] n = 1 To Rng.Count
    [COLOR="Navy"]For[/COLOR] nn = n To Rng.Count
        [COLOR="Navy"]If[/COLOR] Not Rng(n).Address = Rng(nn).Address [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] Abs(CDbl(DateValue(Rng(n))) - CDbl(DateValue(Rng(nn)))) <= 5 [COLOR="Navy"]Then[/COLOR]
                nStr = nStr & IIf(nStr = "", Rng(n) & " / " & Rng(nn), vbLf & Rng(n) & " / " & Rng(nn))
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] nn
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]If[/COLOR] nStr <> "" [COLOR="Navy"]Then[/COLOR]
    MsgBox "The following dates are within 5 days of each other:-" & vbLf & nStr
[COLOR="Navy"]Else[/COLOR]
    MsgBox "All dates within 5 day Limit"
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top