Macro to Format a Row Based on IF Statement

Michael151

Board Regular
Joined
Sep 20, 2010
Messages
247
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> Hello all,

Just need a little help writing a macro that will format a row based on an If Greater Than statement.

In each row, if the date in the column marked “Effective Date” (row 1 header) comes after (is greater than) the date in the column marked “Start Date” (row 1 header) in that row, then the entire row font is changed to red and made bold.

Help is most appreciated – thank you!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Possibly, but the columns containing the Effective Date and Start Date are not always in the same column letters - I'd like to use the header in row 1 to identify. How would I incorporate the conditional formatting into a macro?
 
Upvote 0
Select all the rows you want to format and try this Conditional Formatting formula:

=INDEX(2:2,MATCH("Effective Date",$1:$1,FALSE))>INDEX(2:2,MATCH("Start Date",$1:$1,FALSE))

The formula assumes that the active cell is in row 2 when you enter it. Adjust to suit.
 
Upvote 0
Hi Andrew,

Thanks for that but unfortunately it did not work. Would there be any way to write this as a macro using VBA?

Something like: find "Effective Date" and "Start Date" in row 1 header.
IF Effective Date is greater than Start Date, then make entire row bold, color index 3

I appreciate your help!
 
Upvote 0
It worked for me. In what way didn't it work for you? What do these formula return when entered in a couple of spare cells on your worksheet?

MATCH("Effective Date",$1:$1,FALSE)
MATCH("Start Date",$1:$1,FALSE)
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,254
Members
452,900
Latest member
LisaGo

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