How to find the earliest and latest date when multiple criteria is met.

Plumpychunks

New Member
Joined
Mar 1, 2018
Messages
2
Hi,

Please help.

I have a sheet of data that is outputted from an external source, see below:

Vehicle RegAxleTypeAxlePositionDimensionNew/RetreadBrandPatternEventMileageOTDDateRTDRemovalRegrooved
abc123Drive3L295/80R22.5NewGOODYEARKMAXFitment10241.1.2016243N
abc123Drive3L295/80R22.5NewGOODYEARKMAXExam1200002431.12.201763N
abc123Drive3L295/80R22.5NewGOODYEARKMAXRemoval123321241.1.201843N
789zyxCarry3R385/65R22.5NewPIRELLIAA1Fitment10221.1.2012223N

<tbody>
</tbody>

I would like some VBA to extract the rows that contain the earliest and latest date when columns A,B,C,D,E,G & H are all the same.

I can find methods to extract earliest and latest dates but none that can do it based 7 criteria.

All help would be greatly appreciated.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this for results on sheet2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG01Mar38
[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] txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant, Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range("A1", Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    txt = Join(Application.Index(Dn.Resize(, 8).Value, 0, Array(1, 2, 3, 4, 5, 7, 8)))
    [COLOR="Navy"]If[/COLOR] Not .Exists(txt) [COLOR="Navy"]Then[/COLOR]
        .Add txt, Array(Dn.Offset(, 11), Dn.Offset(, 11))
    [COLOR="Navy"]Else[/COLOR]
        Q = .Item(txt)
          [COLOR="Navy"]If[/COLOR] Dn.Offset(, 11).Value < Q(0) [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] Q(0) = Dn.Offset(, 11)
          [COLOR="Navy"]If[/COLOR] Dn.Offset(, 11).Value > Q(1) [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] Q(1) = Dn.Offset(, 11)
        .Item(txt) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
    [COLOR="Navy"]If[/COLOR] Not .Item(K)(0) = .Item(K)(1) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        Sheets("sheet2").Cells(c, 1).Resize(, 15).Value = .Item(K)(0).Offset(, -11).Resize(, 15).Value
        c = c + 1
        Sheets("sheet2").Cells(c, 1).Resize(, 15).Value = .Item(K)(1).Offset(, -11).Resize(, 15).Value
    [COLOR="Navy"]ElseIf[/COLOR] .Item(K)(0) = .Item(K)(1) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        Sheets("sheet2").Cells(c, 1).Resize(, 15).Value = .Item(K)(0).Offset(, -11).Resize(, 15).Value
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

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