Highlight all rows with today's date

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Good morning!

I'm using this code to highlight all rows that have today's date in column B. It also scrolls the window to today's date.

I'd like to restrict the yellow highlight to the grid and not have it spill off to the right (past column AF as you can see).

VBA Code:
Sub GoToDate()

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
Dim cell As Range
Dim lr As Long
lr = Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
For Each cell In Range("B4:B" & lr)
        If CDate(cell.Value) = Date Then
            cell.EntireRow.Interior.ColorIndex = 6
        Else
            cell.EntireRow.Interior.ColorIndex = xlNone
        End If
Next
       
  Dim iRow As Long
  iRow = Evaluate("match(today(), " & Columns(2).Address & ")")
  Application.Goto Cells(iRow - 22, "B"), Scroll:=True
  Rows(iRow - 1).Select
  Range("B" & (ActiveCell.Row)).Select
  
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
End Sub

GoToDate1.png
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try
VBA Code:
cell.Offset(, -1).Resize(, 32).Interior.ColorIndex = 6
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

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