Highlight cell with next date

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

Is there some VB code that will take a date from cell A1 and then check the dates stored through range E3:J7 and highlight the next date for each row...
so In this example below if today is 14FEB then G3 F4 F5 G6 and G7 will all be highlighted as they are next date from the date in A1, ie 14FEB


CreditCards.xlsm
EFGHIJ
330 Jan13 Feb27 Feb13 Mar27 Mar10 Apr
427 Jan24 Feb24 Mar21 Apr19 May16 Jun
524 Jan24 Feb24 Mar24 Apr24 May24 Jun
604 Jan01 Feb01 Mar29 Mar26 Apr24 May
704 Jan01 Feb01 Mar29 Mar26 Apr24 May
Sheet2


Hope that makes sense and many thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You could use this macro; at the moment it's static but you could use variables for dynamic ranges.
VBA Code:
Option Explicit
Sub Highlight_Later_Dates()
    Dim rw     As Long
    Dim cl     As Long
    Range("E3:J7").Interior.Color = xlNone
    For rw = 3 To 7
        For cl = 5 To 10
            If Cells(rw, cl).Value > Cells(1, 1).Value Then
                Cells(rw, cl).Interior.Color = vbYellow
                Exit For
            End If
        Next cl
    Next rw
End Sub
 
Upvote 1
Solution
You could use this macro; at the moment it's static but you could use variables for dynamic ranges.
VBA Code:
Option Explicit
Sub Highlight_Later_Dates()
    Dim rw     As Long
    Dim cl     As Long
    Range("E3:J7").Interior.Color = xlNone
    For rw = 3 To 7
        For cl = 5 To 10
            If Cells(rw, cl).Value > Cells(1, 1).Value Then
                Cells(rw, cl).Interior.Color = vbYellow
                Exit For
            End If
        Next cl
    Next rw
End Sub
Perfect - that will work nicely - thanks a lot
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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