VBA to Highlight Cells

TattYY

New Member
Joined
Apr 6, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. MacOS
Hi

We have a piece of software that outputs an Excel file once a week, this file has to be organised and edited to show specific information, which is quite a tedious task!
I am trying to produce a macro that will do everything for me, and have almost got everything figured out except the last little bit.

I need it to highlight all rows that have a date before today in column E
This bit of code i have been trying sort of works:

VBA Code:
Dim TDateM As String
  TDateM = Date

endrow = Range("E" & Rows.Count).End(xlUp).Row

For Each cell In Range("E2:E" & endrow)
  If cell.Value < TDateM Then
     cell.EntireRow.Interior.ColorIndex = 6
  End If
Next


It has two small problems though, firstly it only highlights the rows prior to today for this month, anything last month or previous it doesn't seem to work for. This is a bit odd and i don't really understand why it would do this.
Secondly, it highlights the row of the whole workbook, i really want it to only highlight the row in the table. (Columns A to T if that helps)

Anyone able to help?

Ta muchly
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Don't declare TDateM As String, it's a Date; and (2) don't use Entirerow.
VBA Code:
Dim TDateM As Date
  TDateM = Date

endrow = Range("E" & Rows.Count).End(xlUp).Row

For Each cell In Range("E2:E" & endrow)
  If cell.Value < TDateM Then
     cell.Offset(0,-4).resize(1, 15).Interior.ColorIndex = 6
  End If
Next
Bye
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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