Conditional Formating with if then statement - excel

I have a workbook with 2 sheets, Sheet 1 has Column I. Column I is filled with Percent's. I want these %'s formatted as black or red based on conditional formatting.
Sheet 2 has cell B2 filled in with one of the following "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec."
The conditional Formatting formula I thought would be something along with lines of:
If(Sheet2 cell B2 = "Feb" then If the % in Sheet 1 Column I11-I31 the column is less than 10 divided by 12, color Red.
Then the same formula for each month but 9/12 for March and so on.
Hopefully this makes sense. I appreciate everyone taking a look.
Thank you,
Matt

The conditional formulas essentially already follows the IF logic, they are expecting a TRUE / FALSE response:
AND(Sheet2!$B$2="Feb,$I11<(10/12))
The conditional formatting will automatically increment the cell references based on the absolute referencing
The IF Statement is null and void but if it helps you to understand, you would use it like so:
IF(AND(Sheet2!$B$2="Feb,$I11<(10/12)),TRUE,FALSE)
This will then return the TRUE / FALSE that the conditional formatting is expecting

Related

Apply conditional formatting only when specified Cell is empty and other conditions are met

I want to apply conditional formatting (colour a corresponding cell or use symbols [green/orange/red] circles) to a cell
My conditions are the following:
If e.g. cell A4 is empty then
check if date of current cell lies no less than 13 days in the past - if that condition is met -> Format cell Green (or add Green circle in the cell)
check if date of current cell lies no less than 14 and no more than 27 days in the past - if that condition is met -> yellow (yellow circle)
check if date of current cell lies more than 27 days in the past - if that condition is met -> red circle.
If cell A4 is not empty, then do not apply any formatting.
I am kinda stumped with the conditional formatting and I don't know how to combine if-statements in the formula for my specific use case.
Any and all help will be greatly appreciated!
Thanks!
For formatting, you can configure it this way:
The formulas are respectively:
=AND(ISBLANK($A$4), ISNUMBER(D1), TODAY() - D1 <= 13)
=AND(ISBLANK($A$4), ISNUMBER(D1), TODAY() - D1 <= 27)
=AND(ISBLANK($A$4), ISNUMBER(D1), TODAY() - D1 > 27)
Explanation:
Note that D1 is the top left of the range where the conditional formatting applies. It is important for it to match the formulas.
As the formulas for yellow is always true when the formula for green is true, it is important you tick Stop if True like I did (or reverse the order of the formulas).
The formatting applies whenever the formula returns true. The conditions are:
$A$4 (note the $ to fix the cell address) is empty (ISBLANK)
The current cell (D1, corresponding to the top left of the range) is a number (dates are internally numbers in Excel).This condition among other things, prevents the cell from being formatted when it is empty.
The conditions you have given for the date apply. Note that the very last TODAY() - D1 > 27 is unnecessary (if your cell contains a date and is not already colored by green or yellow, then it is bound to be red) but I kept it for consistency.
Finally, you may want to add a condition to ensure the date is in the past (should a date in the future be colored green or yellow?).You have not mentioned anything about future dates so I did not but all you have to do is add D1 < TODAY() or D1 <= TODAY() in each formula to make that work.
You can try this:
=IF(ISBLANK(A4),"",IF(TODAY()-current_cell_date>=13,"Green",IF(AND(TODAY()-current_cell_date>=14,TODAY()-current_cell_date<=27),"Yellow","Red")))
and for symbols you can try this:
=IF(ISBLANK(A4),"",IF(TODAY()-current_cell_date>=13,"✔️",IF(AND(TODAY()-current_cell_date>=14,TODAY()-current_cell_date<=27),"🟢", "❌")))
But make sure you use a font which can interpret unicode.
In order to apply conditional formatting, I advise you to come up with a formula, which gives TRUE for the cases you want to format and FALSE otherwise.
For your one situation, I have created this formula (where I suppose the date will be filled in in cells in "C" column):
=AND(ISBLANK($A$4),NOW()-C4>13)
(You can type this formula in another column (like column "D") and put some date values in "C" column. Then drag and drop that formula down.
One of the crucial points is that $A$4 won't change because of the dollarsign, which indicate an absolute cell reference. Filling in something in that cell or not changes the whole behaviour.
In my screenshot, you have the formula result and the conditional formatting, based on that particular formula:

Applying a single conditional formatting rule across a range

I'm building a yearly shift roster and I'm trying to figure out how to apply the conditional formatting to show where the weekends are. Figuring out how to define the weekend is easy, the problem here is getting the conditional formatting to cooperate with that rule.
Here's how I have my table set up for anyone trying to replicate this:
Row 1 - =LEFT(TEXT(row 2,"aaa"),1) this displays the single letter day of the week based on the date in row 2
Row 2 - The date, formatted to DD. A2 starts with 1/1/2016, B2 is =A2+1 and that is repeated all the way to column NB (=NA+1)
The conditional formatting formula I'm using is =WEEKDAY($A$2,2)>5, applied to $A$1:$A$15. Now this works great for column A, but when trying to copy it over to column B the rule is still referencing column A (however it will apply it to column B). What I'm struggling to figure out is how to get the conditional formatting rule to look at all 365 columns and then apply the conditional formatting to that single column and not the entire range. The end result here would be that the weekdays have no fill applied while the weekends are shaded.
The solution to this is to use =WEEKDAY(INDIRECT(ADDRESS(2,COLUMN())),2)>5.
Here's what's going on in each part, starting inside and working out:
COLUMN() returns the column number of the current cell (A=1, B=2, C=3, etc...), so for the sake of this example let's say you had cell A2 selected, COLUMN() will then return 1.
ADDRESS(2,1) returns a TEXT string of the absolute cell reference ("$A$2"), in this case locked to row 2.
INDIRECT("$A$2") converts the text string into the A2 cell reference.
WEEKDAY($A$2,2) evaluates the date in cell A2 (1/1/2016) and returns a numerical value based on what date of the week it is. The 2 argument sets the week as Monday (1) through Sunday (7). In this example WEEKDAY() will return a value of 5 (Friday).

Excel 2010 - Conditional formatting, color adjacent cells in same row

Is is possible in Excel 2010 to set a conditional formatting rule to highlight all not empty cells in a row when the cell in particular column has a particular value?
I have a report in which every row identify a day. I would like to colour in grey the rows relative to Saturday and Sunday. The day is stored in column C.
I know how to highlight cells in column C, but how can I easily extent the format of cell C to the adjacent not empty cells in the same row?
This is easy to do without a macro and without using INDIRECT function
Assuming you have data starting at row 2 and that the "day" in column C is a text value then do this:
Select whole range of data, e.g. A2:J100
apply in conditional formatting the formula that needs to apply to the first row, e.g.
=AND($C2="Saturday",A2<>"")
That will apply formatting to all cells in the range if col C of that row is "Saturday" and the cell itself is not blank. Note C2 needs a $ in front because it applies to C for the whole row A2 doesn't need $
If you want to apply to Saturday and Sunday the same type of formatting then use an OR, i.e.
=AND(OR($C2="Saturday",$C2="Sunday"),A2<>"")
....or if the column C entries are actual dates make that
=AND(WEEKDAY($C2,2)>5,$C2<>"",A2<>"")
See example workbook with that last CF formula demonstrated
Taking inspiration from John answer in this thread, I've used the "indirect" function on the conditional formatting.
Select Conditional Formatting
Select New Rule
Select "Use a Formula to determine which cells to format"
Enter the Formula, =WEEKDAY(INDIRECT("c"&ROW()))=1 # for Sundays
Enter the Format you want (text color, fill color, etc).
Select OK to save the new format
Open "Manage Rules" in Conditional Formatting
Select "This Worksheet" if you can't see your new rule.
In the "Applies to" box of your new rule, enter =$A$1:$J$35 (or however wide/long you want the conditional formatting to extend depending on your worksheet)
Do it again, this time inserting the Formula, =WEEKDAY(INDIRECT("c"&ROW()))=7 # for Saturdays
There is only an issue with this formula. When the cell in Column C is empty it will be read as 7, therefore the row will be formatted as if it's a Saturday. Do you know why?

Formatting a cell based on perpendicular row/column values

Trying to create a Gantt chart look in Excel. I have two columns, A and B (A = start date, B = End Date).
Across the top of the page (Row 2) I have a column with a date for every date of the project (custom formatted with "d" for readability, with the name of the month in Row 1.)
I'm now trying to apply conditional formatting rules to turn the cell in the column a specific colour (say, green) if:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
I've dug through a few answers recommending ADDRESS() and INDIRECT(), but I'm stumped on getting this to work. Any thoughts?
You can use AND to combine the conditions. I'm assuming the 'Gantt chart' starts as from column C and the active row is 2 here.
Select C2 and the rest of the row (to 31, 30 or 28/29 depending on the number of days in the month).
Pull up conditional formatting with formula and put:
=AND(C2>=$A2,C2<=$B2)
Pick the format fill green and that should do it
In conditional formatting if you use the first cell of your selection in the formula it automatically turns that into a relative formula.
For example if you use the formula: =A1>5 and select cells A1:B5 it will check each cell to see if its >5 not just cell A1 (so it automatically increments the row and the column for you). Usually this is preferred over using indirect but sometimes indirect is necessary.
So using indirect you can utilize the row() and column() functions. So in your example:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
Would look like:
=AND(INDIRECT("A"&ROW()) >= INDIRECT(CHAR(COLUMN()+64)&"2"), INDIRECT("B"&ROW()) <= INDIRECT(CHAR(COLUMN()+64)&"2"))
Hopefully that helps
It works for me without ADDRESS or INDIRECT. This is the formula inside the conditional formatting. If I have to guess what's going on, it's most likely that you are not placing the proper anchors ($).
=AND(C$2>=$A3,C$2<=$B3)

Conditional formatting between values? Do I need to restructure my spreadsheet?

I would like to format all cells within the range (essentially fill them with color) of start date to end date in each row.
For example, in the picture below, you can see that cells B8 and C8 contain start and end dates, 1/1/2013 and 3/24/2013 respectively. It is formatting correctly, coloring in cells D8:08.
The header cells contain dates formatted as text. For example, cell D3 (the first J), is actually the date 1 January 2013. Similarly, cell E3 (the second J), is actually the date 8 January 2013, cell F3 is 15 January 2013, and cell G3 is January 22 2013. The pattern repeats for each month, only listing the 1st, 8th, 15th, and 22nd of each month.
PROBLEM: I believe I've got it working most of the way, but it seems to not format correctly if the dates fall outside of the dates assigned in the header cells.
For example, if I assign a start and finish date of 5/31/2013, no cells are highlighted. See below image.
I assume that's because I only have up to May 22 2013 in my header cells, but I would like to keep it to four weeks in each month.
Below is the formula I used to format, which I then applied to the whole range D8:AY43, which is essentially the whole task hierarchy.
=(D$3>=$B8)*(D$3<=$C8)
Is there anyway to change this formula to accommodate my issue (cells won't highlight if they fall outside the range of values designated in the month column headers?) Or do I have to restructure my spreadsheet?
Thanks!
An alternative while keeping "4 weeks" per month would be to change the dates in header column to reflect the end of a "week", rather than the start. So instead of January 1, January 8, January 15, etc., use January 5, January 12, January 19, & January 31. You'll need to tweak your formula to account for that change, but it would preserve the structure of your workbook.
Not 100% certain what you're doing (looks like a Gantt chart?) but looks like you're just trying to evaluate whether the date in Column D is between the start and end dates in cols B & C, in which case:
=AND($B8<=D$3,$C8>=D$3)*1
This tests whether the date in D3 falls between the start/end dates defined in columns B & C, and returns "1" if true, and "0" if false.
To put this in conditional formatting, do the rule like:
=AND($B8<=D$3,$C8>=D$3)*1=1
Here is what the rule should look like in the Conditional formatting dialog:

Resources