Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 9th, 2011, 03:38 PM
Authorized User
Points: 308, Level: 6
Points: 308, Level: 6 Points: 308, Level: 6 Points: 308, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2009
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default IF statement in conditional formatting

Has anyone tried using an IF statement within conditional formatting? If so, I would like to know if it worked, and if so, was it straight forward or were there special issues to be dealt with, and how you set it up. I very much do not want to have to try to put it into VBA as it would be nightmarish to get it into all the cells and keep it working correctly.

I would like to use a formula something like the following in the conditional formatting formula.

IF(cell above = x, format a, format b).

Or better yet, I would like to use a nested IF statement. Something like:
IF(cell above = x, format a, IF(cell below=y,format b,format c))

I don't see how this can be done in the manage rules box of Excel 2007, but if it can be done, someone on this site knows how.
Reply With Quote
  #2 (permalink)  
Old May 9th, 2011, 11:10 PM
Friend of Wrox
Points: 689, Level: 9
Points: 689, Level: 9 Points: 689, Level: 9 Points: 689, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts

hey robert,
select the cell you want to conditionally format, then on the home tab, click on "conditional formatting," then on "manage rules."

Now click on "New rule," then on "use a formula to determine which cells to format"

Add your condition that should be applied last. So something like "=cell below= y". Whatever your formulas are, they need to evaluate to TRUE or FALSE.

Then select the formatting you want applied, hit ok.

Then do the exact same thing for "cell above," i.e. hit "New rule,", then "use a formula..."

Your "format C" is your default in the equation you gave as the example, so you shouldn't need to enter a formula for that, just set that as the format for the cell.

You might have some logic issues you'll have to resolve. What if, in your formula,

"IF(cell above = x, format a, IF(cell below=y,format b,format c))"

both cell above is x AND cell below = y?

You can move the order the rules get applied with the two arrows to the right of "delete rule." Also, don't forget you can use the And() and Or() functions in each/both of the rules if that will make the logic work to format the cells as you need. Just make sure that whatever you put in each rule as a formula, it can only evaluate to TRUE or FALSE.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formatting r05579 SharePoint Development 0 February 19th, 2010 12:08 PM
conditional formatting jeremy1048 Access 4 July 3rd, 2008 11:20 AM
Conditional formatting vemaju Excel VBA 2 June 6th, 2007 04:41 AM
Conditional Formatting Corey Access 1 November 8th, 2005 12:18 AM
Conditional Formatting... In Access??? lguzman Access VBA 2 September 23rd, 2004 03:52 PM

All times are GMT -4. The time now is 05:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.