VBA color code on oldest date

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
Hi Can someone please help me, i need a vba code where it should green color on oldest date with in one ID.

below is the sample of data.


[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]ID[/TD]
[TD="class: xl65, width: 64"] Date[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]338583883[/TD]
[TD="class: xl67, align: right"] 08/11/2005[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]338583883[/TD]
[TD="class: xl67, align: right"]06/23/2003[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]352556553[/TD]
[TD="class: xl67, align: right"]06/16/2008[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]352556553[/TD]
[TD="class: xl67, align: right"]09/16/2008[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]855585635[/TD]
[TD="class: xl67, align: right"]07/22/2015[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]855585635[/TD]
[TD="class: xl67, align: right"]09/30/2017[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]855585635[/TD]
[TD="class: xl67, align: right"]09/30/2017[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]853523322[/TD]
[TD="class: xl67, align: right"]09/27/2016[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]853523322[/TD]
[TD="class: xl67, align: right"]06/21/2012[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]828533758[/TD]
[TD="class: xl67, align: right"]03/24/2009[/TD]
[/TR]
[TR]
[TD="class: xl66, align: right"]828533758[/TD]
[TD="class: xl67, align: right"]09/11/2017[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Sub ConditionalFormatting()
Dim IdRange As Range
Dim DateRange As Range
'Adapt to your data ranges
Set IdRange = Range("A2:A12")
Set DateRange = Range("B2:B12")
For Each cell In IdRange
    If Cells(cell.Row, DateRange.Column).Value = Application.WorksheetFunction.MinIfs(DateRange, IdRange, cell.Value) Then
        Cells(cell.Row, DateRange.Column).Interior.Color = 5287936
    End If
Next cell
End Sub
 
Upvote 0
Another option:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG19Nov19
[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]
[COLOR="Navy"]Set[/COLOR] Rng = Range("A2", 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
    [COLOR="Navy"]If[/COLOR] Not .exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        .Add Dn.Value, Dn.Offset(, 1)
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]If[/COLOR] Dn.Offset(, 1) < .Item(Dn.Value) [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] .Item(Dn.Value) = Dn.Offset(, 1)
        [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] .exists(Dn.Value) And Dn.Offset(, 1) = .Item(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        Dn.Resize(, 2).Interior.Color = vbGreen
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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