Extracting Earliest and Latest Dates from Cells

TheOddGirl

New Member
Joined
Apr 1, 2018
Messages
11
I have a spreadsheet with 20,000 rows of data that I need to get the earliest and latest dates into one row.

Example, for Shop1 I would need the start date to be 01/01/2018 and the end date to be 05/04/2018 recorded in a column to the right so I can sort by that column and get rid of data that I don’t need. Can anyone offer any help with this please?

[TABLE="width: 289"]
<tbody>[TR]
[TD]ShopID[/TD]
[TD]ShopName[/TD]
[TD] Startdate[/TD]
[TD] Enddate[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name1[/TD]
[TD]01/01/2018[/TD]
[TD] 05/02/2018[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name1[/TD]
[TD]01/03/2018[/TD]
[TD] 05/04/2018[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name2[/TD]
[TD]01/01/2017[/TD]
[TD] 05/02/2017[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name2[/TD]
[TD]01/07/2017[/TD]
[TD] 05/09/2017[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Name3[/TD]
[TD]01/01/2018[/TD]
[TD] 28/02/2018[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Name3[/TD]
[TD]01/03/2018[/TD]
[TD] 30/10/2018[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If MINIFS and MAXIFS functions are available on your system...

In E2 enter and copy down:

=MINIFS(C:C,A:A,A2)

In F2 enter and copy down:

=MAXIFS(D:D,A:A,$A2)

Otherwise, control++shift+enter, not just enter, and copy down:

E2 >>

=MIN(IF($A$2:$A$7=$A2,$C$2:$C$7))

F2 >>

=MAX(IF($A$2:$A$7=$A2,$C$2:$C$7))
 
Upvote 0
NB:- This code will modify/Update your data and remove unwanted rows, see Code Notes.
Code:
[COLOR=navy]Sub[/COLOR] MG01Apr22
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] q [COLOR=navy]As[/COLOR] Variant, K [COLOR=navy]As[/COLOR] Variant, nRng [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Set[/COLOR] Rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
[COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
     .Add Dn.Value, Array(Dn.Offset(, 1), Dn.Offset(, 2))
[COLOR=navy]Else[/COLOR]
    q = .Item(Dn.Value)
        [COLOR=navy]If[/COLOR] Dn.Offset(, 1) < q(0) [COLOR=navy]Then[/COLOR] q(0).Value = Dn.Offset(, 1)
        [COLOR=navy]If[/COLOR] Dn.Offset(, 2) > q(1) [COLOR=navy]Then[/COLOR] q(1).Value = Dn.Offset(, 2)
        [COLOR=navy]If[/COLOR] nRng [COLOR=navy]Is[/COLOR] Nothing [COLOR=navy]Then[/COLOR] [COLOR=navy]Set[/COLOR] nRng = Dn Else [COLOR=navy]Set[/COLOR] nRng = Union(nRng, Dn)
    .Item(Dn.Value) = q
[COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
'[COLOR=green][B]NB:- This line will remove all the other rows, except Max and Min date rows.[/B][/COLOR]
[COLOR=navy]If[/COLOR] Not nRng [COLOR=navy]Is[/COLOR] Nothing [COLOR=navy]Then[/COLOR] nRng.EntireRow.Delete
[COLOR=navy]End[/COLOR] With
Application.ScreenUpdating = True
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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