Get instant live expert help with Excel or Google Sheets
“My Excelchat expert helped me in less than 20 minutes, saving me what would have been 5 hours of work!”

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.

How to Combine Conditional Formatting with an IF Statement

Read time: 29 minutes
One of the methods to achieve Conditional formatting based on a custom formula is using the IF statement. The IF function works on the IF/THEN/ELSE condition syntax. For example, “if the given argument is TRUE, THEN return this value, ELSE that value.” The IF function performs a logical test and returns one value for a TRUE result and another for a FALSE result.

Combine conditional formatting with an IF statement

Syntax 

=IF (logical_test, [value_if_true], [value_if_false])

But in conditional formatting, IF/THEN/ELSE syntax cannot be applied in a single rule. Conditional formatting is applied using IF/THEN logical test only. It must return TRUE for conditional formatting to be applied.

For example, if you want to apply conditional formatting using a condition that “If a cell value is greater than a set value, say 100, then format the cell as RED, else format the cell as GREEN”. So, you can see that it requires two rules to perform the conditional formatting, one for greater than 100, and one for less than 100.

You can apply more than one condition by creating more than one rule in conditional formatting. You can also use logical functions like AND and OR to create a rule set and apply conditional formatting in Excel.

Examples using conditional formatting with IF/THEN conditions

Let’s look at the scenarios to see how to use IF/THEN logical test in conditional formatting to highlight the targeted values. If you want to highlight the invoices in data range of A2:C13 which are due in the month of April, then you need to test the IF/THEN logical condition on date range in column B, if the month is equal to April, by using following custom formula in conditional formatting.=MONTH($B2)=4

First, select the data range A2:C13, then go to:

Conditional Formatting (on the Home tab) > New Rule> Use a formula to determine…> Enter the above formula in Edit Rule Description window> Choose the Format Fill to preview and press OK

How to Combine Conditional Formatting with an IF Statement

Please note that you have to fix the column by making it absolute using $ sign with it, and keep the row number free or relative to change. Hence, the formula will check each row of the specified column in the selected range, test the IF/THEN logical condition and will return TRUE and FALSE.

This rule will be evaluated in all active cells of locked column B one by one ignoring other cells in columns A and C. When the MONTH function in a cell of column B returns number 4 (April), the rule will return TRUE for all the active cells in that row and conditional formatting will be applied to that entire row as shown below.

How to Combine Conditional Formatting with an IF Statement

Now, if you want to conditionally highlight the two largest amount invoices due in the month of April, then you can achieve this by creating a rule set based on array formula using AND, LARGE and IF statement as per the following syntax.

=AND(criteria,$C2>=LARGE (IF(criteria, values),2)) =AND(MONTH($B2)=criteria,$C2>=LARGE (IF(MONTH(date)=criteria, amount),2)) =AND(MONTH($B2)=4,$C2>=LARGE(IF(MONTH($B$2:$B$13)=4,$C$2:$C$13),2))

By applying this custom formula, you can highlight the two largest amount invoices in the month of April. LARGE with IF function will generate a series of values and compare them with each value in column C. AND function will test the logical conditions in each cell of column B and C both one by one and will return TRUE where both conditions will be met. Have a look below.

How to Combine Conditional Formatting with an IF Statement

Need some additional help with Conditional Formatting or have other questions about Excel? Connect with a live Excel expert here for some 1 on 1 help. Your first session is always free. 

Are you still looking for help with the Average function? View our comprehensive round-up of Average function tutorials here.

Did this post not answer your question? Get a solution from connecting with the expert.

Another blog reader asked this question today on Excelchat:
Solution examples
I have a list or people who are ranked in numbers from 3 to 6 I need to recognize the contents of each multiple cells and create an equivalent letter. for that value into another column. e.g. Cell E1 = 3 to show in new cell that row (H1) the letter "C" I have multiple rows with different values in column "E" Can this be done?
Solved by I. J. in 30 mins
Hello good afternoon, I have a problem with excel. I need a formula to compare data between 3 columns and give me the result in a fourth column
Solved by X. B. in 58 mins
I want to display a range of cells if they meet a specific criteria. I want to display a name IF it does not equal one of three options AND there are any numbers contained in a range of cells
Solved by G. F. in 60 mins
can you teach me the steps to create a nested if function, and to nest an AND function inside of an IF function?
Solved by A. Q. in 22 mins
I can't get this formula correct, can someone assist? I am trying to create a date for our posting process based on the payment terms. If a customer is paying biweekly, with a start date of 3/1/2018, etc. I want to be able to run daily what customers will need to be charged. =IF(OR(D2="MONTHLY",$C$6+30,")*IF(D2="WEEKLY",$C$6+7,"")*IF(D2="BIWEEKLY",$C$6+14,""""))
Solved by S. H. in 9 mins

11
Leave a Comment

avatar
11 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
9 Comment authors
AdilSamBenDamienKevin Recent comment authors
newest oldest
Carol
Guest
Carol

Hi there Im trying to apply conditional formatting to cells that do not contain a formula. I am using excel 2010 so Ive used a macro to create the =ISFORMULA function but the conditional formatting is not working if the formula returns FALSE

Sam
Guest
Sam

I am using duplicate control in excel through Conditional Formatting, total 18,500 nos. of Rows are existing in the sheet. Filter with Highlight Color is not working now. Please suggest me the best way to check duplicacy..

Sam
Guest
Sam

I want to copy Conditional formatting rules, but also the change the rule it applies to based on the cell it is in.

Brady
Guest
Brady

Trying to use conditional formatting to color code cells that are greater or less than another cell. However there is text in the cells and the conditional formatting isn’t correctly color coding values that are higher or lower. Any ideas?

Carl
Guest
Carl

I have a formula of color changing (conditional formatting), just need someone to help fix it!

Daniel
Guest
Daniel

I want to be able to use conditional formatting to highlight a column of different values in comparison to another column, but all the values vary. I know how to use conditional formatting to highlight a value over or under a set amount but not a varied one?

Kevin
Guest
Kevin

How to Use Conditional Formatting to Change Cell Background Color Based on Cell Value not for only 1 cell but all the cells depending upon the cell value entered. for example I have four status as 1 )open 2) Resolved 3) Overdue 4) hold. I want the cell should change color as green if resolved and red as overdue and open as brown and hold as yellow.

Damien
Guest
Damien

Hi, I’d like to create format table for work due date 7 days before allot required(like conditional formatting) with different scenarios of production stages. Kindly please help me

Ben
Guest
Ben

I am struggling to create a conditional formatting formula that is dependent on the contents of another cell. which changes color depending on the proximity of the contents of the second cell

Sam
Guest
Sam

I have an issue with my pivot table. I am trying to set the conditional formatting on my pivot. The data in my pivot will change daily. I would like my rule to apply to my data as it adjusts daily. I set my rules but when I filter or make any changes to the data my conditional formatting rule is taken off. How can I get this conditional formatting to stay in place?

Adil
Guest
Adil

I need help with conditional formatting, I cannot seem to make the rules work and apply to the whole sheet.

Subscribe to Excelchat.co

Get updates on helpful Excel topics

Subscribe to Excelchat.co

Did this post not answer your question?
Get a solution from connecting with the expert

Another blog reader asked this question today on Excelchat:

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.
Trusted by people who work at
Amazon.com, Inc
Facebook, Inc
Accenture PLC
Siemens AG
Macy's
The Allstate Corporation
United Parcel Service
Dell Inc