Macro to highlight a row if cells match value

sgriffis - Feb 22, 2011 at 09:02 AM
 sgriffis - Feb 22, 2011 at 10:29 AM

I sorry but I am very new to macros and trying to create one in Office 2003. I need to bold a row if for example column E is greater than a given value and column H is today's date or earlier.

So if Column E >= 50 AND column H is today or an earlier date then bold that row.

Any help is appreciated.


2 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen January 16, 2023 549
Feb 22, 2011 at 09:45 AM
Hi Sgriffis,

Try this code:

Sub test()
Set MR = Range("E1:E100")
For Each cell In MR
If cell.Value >= 50 And cell.Offset(0, 3).Value <= Date Then cell.EntireRow.Font.Bold = True
End Sub

You stated that you are very new to VBA so here's how to implement the code:

In excel goto top menu > extra > macro > visual basic editor (or ALT F11).
A new window will open, goto top menu > insert > module.
Copy the code in the big white field.
Adjust the name "test" to whatever name you want to give this macro.
Adjust the range ("E1:E100") to whatever range you use in your file.
You can now close the visual basic editor window.
Back at excel goto top menu > extra > macro > macro's (or ALT F8).
Choose to run the macro "test" or whatever name you changed it into.

Note: Actions made by macro cannot be undone using the blue arrows!
So it is always best to save before running a macro, if the desired result doesn't show up you can simply reload your file.

Best regards,