I am having a grading scale and would like to map my grades to the grading scale.
I tried to use just VLOOKUP(), however, the formatting is not taken and also some bounds are breached.
Any recommendation, how to use the formatting in my resultCell?
You would use conditional formatting.
To get the result name to print, use this formula:
=INDEX($A$2:$A$6,MATCH($E2,$B$2:$B$6,1))
For the Number:
Reproduce these steps:
Change your table so the values aren't equal to each other, as in, the Perfect(Max) shouldn't be the same as the perfect-(Min).
Take the result cell, and go to Conditional Formatting.
Highlight Cell Rules > Between
Select the cells that contain the min and max for that particular color.
Select "with" Custom Format
Select the color you want for that result
Repeat for each color you want used.
For the "Perfect" Result:
Repeat the same as above, except use Highlight Cell Rules > Equal To Then select the appropriate values for each color, ie, "Perfect" for Dark Green, etc. Use the actual cell address.
You will want to leave the fourth parameter of the =VLOOKUP() formula as TRUE for an approximate match. This allows you to get "map/lookup" values in-between the ranges of numbers.
This should do the trick, just play with the cutoffs to get the behavior you desire:
Various adjustments that would normally be considered quite minor might make this question a lot easier to answer, but taking the details as they are (with Start assumed to be in C2, 3,4 assumed to be three and four tenths and the required output as shown in G3 and G4), in G3 and copied down to suit:
=IF(F3=0;"perfect";IFERROR(INDEX(B:B;MATCH(F3;C:C;0)-1);INDEX(B:B;MATCH(F3;C:C))))
Select ColumnG, HOME > Conditional Formatting – New Rule…, Format only cells that contain, Format only cells with::
Specific Text
containing
perfect
Format…, dark green fill, OK.
Repeat rules as below:
Where the order is important because “contains low” will find both low and low- so orange should be applied after red.
What might have made things easier is:
To have columns B and C switched over (ColumnD is not required) to allow use of VLOOKUP instead of INDEX/MATCH.
To change the break points (so that the START values are not the end of the previous range and part of that and hence the need to attempt an exact match before resorting to an inexact one).
To classify without relying on the - for differentiation (to avoid the ordering issue mentioned above).
To place perfect in B2, to avoid the equality issues mentioned in a comment (and I think not addressed in the accepted answer).
Related
I have two columns to compare. All cell values come from the ROUNDUP function. =ROUNDUP(C6/D12,0) etc.
I want the larger, or equal, of the two in each row to be green and the smaller red. Using the formula, it does not work as expected. If I do the same with numbers typed, not the formula, it works. It appears the formatting applies to the formula and not the value.
That is the first half of the problem. I also want to autofill/paint the conditional formatting to numerous cells, but it always compares to the top left cell, rather than the two cells on the same row.
If I use the color scales formatting it works, but I do not want the scales, just red/green.
It seems hard to believe that what I want to do is not possible. Can someone please help me with this. Thanks in advance.
In conditional formatting, under 'use a formula to determine which cells to format', you need to enter
=A2=MAX($A2,$B2)
to highlight the larger cell and (as a separate rule)
=A2=MIN($A2,$B2)
to highlight the smaller cell.
Note that in the case where both cells have the same value, they will both be either coloured red or green depending on the precedence of the rules. If the 'green' rule comes first,
it will look like this:
Conditional formatting is almost its own little science within Excel. It may be more useful to find youtube tutorials on the topic than depend on a text explanation here. But the central theme is this.
You will use location locking (the dollar sign or F4) in front of the letters so that any cell to which the format is applied knows you specifically mean columns E and F, for instance.
Example: Assume your first row goes from A5 to M5, and the condition values are in E5 and F5.
I find it easiest to format one row with the rules I want, test them, and then use the format painter or copy -> paste format along with careful use of $ locking.
Drag over and select the entire row of cells A5:M5
Conditional Formatting -> New Rule -> Use a formula to determine which cells to format
In the formula field enter =$E5>$F5. Excel gets weird and often inserts double quotes. If you save the rule and go back in, it may say ="$E5>$F5" and if so delete the double quotes.
Click Format and create the cell format you want.
With A5:M5 still selected, add another rule and format for ="$E5<$F5"
The $ sign works the same way as it does in a formula. All of the columns get their format based on columns E and F, but all of the rows base their formula on the E and F values in that same row.
Suppose I want to color scale complete rows on the basis of values in a column (using excel inbuilt color scale option in the conditional formatting menu). How do I achieve this? Please see the following image
I found a property Range.DisplayFormat.Interior.Color in this post, at Mrexcel. Using this property I was able to get color of conditionally format cell and use it for the other rows. Catch is, it works only excel 2010 onwards. I have excel 2010 so it worked for me.
Here is the exact code -
For i = rowStart To rowEnd
For j = columnStart To columnEnd
Cells(i, j).Interior.Color = Cells(i, 4).DisplayFormat.Interior.Color
Next
Next
If I understood you correctly I have been battling with the same issue. That is to format entire rows based on the values in one column, wherein the values have been formatted via Excel's Color Scales.
I found this truly ridiculously easy workaround that involves copying your color scaled cells into word, then back into excel after which you can delete the values and substitute them with whatever values you want without changing the format:
https://superuser.com/questions/973921/copy-conditional-formatting-3-color-scheme-to-another-tab/973974#973974?newreg=fc5ca6d04a5a406fa39cd4796b6a539e
All credit to user Raystafarian
You don't need VBA to do this, really.
But there are two things to point out from the start:
You won't be able to achieve your desired behavior with a single conditional formatting rule; you'll have to have a separate rule for each sales-based row color definition.
I have found that it is much easier to achieve desired Conditional Formatting behavior in Excel using Named Ranges for the rules instead of regular formulas.
If you're still on board with me after that preamble, follow these steps to create your named range and then create your conditional formatting rules.
First, select the first sales cell on your sheet (uppermost row)
Next, give the cell a name, "SALES". Do this by pressing Ctl+F3, or select Formulas->Name Manager from the ribbon. Then select New... In Name: enter SALES and in Refers to: enter =$XN where X is the column of the first sales cell, and N is the row number. Hit Enter.
Now select the entire cell range you wish to exhibit this behavior
Select Home->Conditional Formatting->New Rule...
Select Use a Formula to Determine Which Cells to Formatand enter =SALES=number where number is the sales number you wish to trigger a color
Select Format and the Fill tab. Now you need to decide what background color you want for the sales number you chose. You can also choose other formatting options, like the font color, etc.
Hit OK, OK, OK. Repeat steps 3 to 6 for each different sales figure/color combination you want. If you want a color for "all sales less than X", in your rule you will enter =SALES<number (< is "less than"; you can also do <=, which is "less than OR equal to"). If want the rule to happen when between two numbers, you can do =AND(SALES<=CEILING, SALES>=FLOOR), where ceiling and floor are the upper and lower bounds. If you want a color for "all sales greater than X", you can do =SALES>number.
EDIT:
To make entering your conditional formulas a bit easier, you can use the "Stop If True" feature. Go to Home->Conditional Formatting->Manage Rules, and in the dropdown menu choose This Worksheet. Now you will see a list of all the rules that apply to your sheet, and there will be a "Stop If True" checkbox to the right of each rule.
For each row color rule, put a check in the "Stop If True" checkbox. Now your formulas can be like this (just for example):
=Sales>25 for the green rule
=Sales>10 for the yellow rule
=Sales>0 for the Red rule
Etc, instead of like this:
=AND(Sales>0,Sales<=10) for the Red rule
=AND(Sales>10,Sales<=25) for the yellow rule
=Sales>25 for the green rule
The Stop If True box means that once a formatting rule has been applied to a cell, that cell will not be formatted again based on any other rules that apply to it. Note this means that the order of the rules DOES MATTER when using Stop If True.
You can do this with the standard conditional formatting menu, no need for VBA. You choose the option of specifying your own formula, and you can refer to a cell (lock the column with the '$') other than the one you want to highlight.
Background Reading
I think I have found a solution for this. I can achieve a colour scale of 5 degrees for any range of numbers across all cells in the row with the option of only affecting cells containing data.
This is achieved by creating 5 conditional formatting rules based around the following:
=AND(D4<>"",$D4<>"",($D4-(MIN($D$4:$D$20)-1))/(MAX($D$4:$D$20)-(MIN($D$4:$D$20)-1))*5<=2)
The first argument in the AND function D4<>"" is used if you only want cells containing data to be affected, remove this if you want the whole row of data colour coded.
The second argument, $D4<>"" points to the cell in the row that contains the value to evaluate - remember the $ to lock the column
The third argument, $D4-(MIN($D$4:$D$20)-1))/(MAX($D$4:$D$20)-(MIN($D$4:$D$20)-1))*5<=2 evaluates the position of the value within the entire range of values and converts this into a number between 1 and 5, changing the *5 at the end of this argument allows you to have more steps in your colour sequence. You will need to add more conditional rules accordingly. The <=2 indicates this is the second colour step in the sequence.
Colours 3 and 4 use the same condition but the <=2 is changed to <=3 and <=4 respectively.
The first and last colour stop need a small modification if you always want the lowest number in the range to be the first colour stop and the highest number in the range to be the highest number stop.
For the minimum number in the range, adapt as follows:
=AND(D4<>"",$D4<>"",OR($D4=MIN($D$4:$D$20),($D4-(MIN($D$4:$D$20)-1))/(MAX($D$4:$D$20)-(MIN($D$4:$D$20)-1))*5<=1))
the introduction of OR($D4=MIN($D$4:$D$20) catches the first number in the range
Similarly
=AND(D4<>"",$D4<>"",OR($D4=MAX($D$4:$D$20),($D4-(MIN($D$4:$D$20)-1))/(MAX($D$4:$D$20)-(MIN($D$4:$D$20)-1))*5<=5))
Using OR($D4=MAX($D$4:$D$20) catches the maximum number in the range
Note that Stop if True must be ticked for all conditions and the conditions must be sorted from minimum to maximum steps in the sequence.
Image of Conditional Formatting Rules Manager
I have used one formula to change the font colour if a cell contains the text "complete" & another formula to add a light blue fill to the entire row if the word "odd" appears in a cell which is in a different column to the first formula.
The conditions seem to clash & although I have changed and played with the order of the conditions & checked there is no conflict in the fill/background or the font colour, even when changing the font colour manually again the fill from the second formula returns the font the cell to black although it is set to automatic in the conditional formatting rule with the fill ?
I wonder where i am going wrong as everything suggests the two conditions should work fine together though when the fill is applied the font goes back to black when it should be green ?
Have you any suggestions ?
I found the issue, I needed to press clear on the font section of the formatting on the fill condition and then clear on the fill. Basically as a rule I press clear on anything not required in that condition and this seems to avoid the conflict and run upto 6 rules on the same cell with no problems!
You can combine multiple conditional formats overlapping cells/rows. (Excel's just a little picky that you do it just right!)
Always use New Rule as opposed to using the built-in rules.
Choose Use a formula to determine which cells to format.
For your example question, I populated the cells as shown above. Select cell B4 and set the conditional formatting as above =($B4="complete") . Note that I removed a $ (dynamic vs absolute cell reference) that was automatically filled in, so that I can fill the formatting's formula down.
Highlight entire Row 4 and set the conditional formatting as below. Again, note the modified $.
When it's working properly, copy entire Row 4, select the rows to which the formatting should be applied, and Paste Formatting.
[
Obviously the steps will vary for you depending on your data and what's in the neighboring cells whose formats you may or may not want affected by the formatting and copy/pasting.
Let me know if that works for you.
From my experience with conditional formatting, I believe that it applies a format to the entire cell rather than individually modifying fill or font colour, so formats will not combine. I had a similar situation and solved it by creating an additional rule. In your case, one that applies your desired font colour and background fill to the 'complete' cell if the same row also contains 'odd' using the AND() function.
I'm trying to make a formula that will color code three cells that are directly above/below each other. The color coding depends on the sum of three other cells that are directly above/below each other, and directly across from the cells to be colored.
This part is easy. The rule is:
Forumula: =SUM(H5:H7)>30
And it applies to:
$E$5:$E$7
However, the issue is that when I copy the cells that are being colored (E's) to three more cells below them for the next batch, the relative formula does not work as expected. It applies the formula on H6:H8 (+1) instead of H8:H10 (+3).
Is there a way to get the relativeformula to work as expected? I hope this was clear enough. I know it's hard to visual a spreadsheet, but ultimately I need the relative forumla to add +3 instead of +1 when it is copied.
Problem:
If I correctly understand, what you are trying to achieve is to have the range E5:E7 formatted strictly based upon H5:H7, then the next three-cell range - E8:E10 - based upon H8:H10 and so on. You can do this by implementing the below solution:
Solution:
Step 1: Setup Columns as Below
Step 2: Implement Conditional Formatting as Below
Explanation:
I have recreated your issue and I see your problem; it was not that obvious until I played around with changing values of different cells in Column H.
Apparently, this has to do with how Excel interprets your instructions (formula) supplied under conditional formatting. To understand this let's first focus on the behavior of cells E5, E6 and E7 as a function of values in Column H.
With the formula =SUM(H5:H7)>30 did you notice that:
E5 format depends upon =SUM(H5:H7),
E6 format depends upon =SUM(H6:H8), and
E7 format depends upon =SUM(H7:H9) and
when you copy the range E5:E7 three cells down into E8:E10, the expected behavior is:
E8 format depends upon =SUM(H8:H10),
E9 format depends upon =SUM(H9:H11), and
E10 format depends upon =SUM(H10:H12)
And this is exactly how the range E8:E10 will behave once the above solution is applied.
A partial answer to your question has to do with your relative formula - =SUM(H5:H7) - under conditional formatting. Using this formula causes $E$5 to use =SUM(H5:H7) to determine its formatting, $E$6 to use =SUM(H6:H8) to determine its formatting, and so on. This ultimately leads to issues with the conditional formatting even before you begin copying the cells down.
EDIT: (piggy-backing off #Bharat Anand's answer)
#Bharat Anand's answer appears to be the best way to accomplish this question.
#Thisisstackoverflow requested clarification (under the accepted answer) and I'm hoping my screenshot below will help.
I set my worksheet up in what I believe is the exact same manner as #Bharat Anand, and it seems that the column letters may have been off. Setting mine up like this made it work correctly.
EDIT: (clarification for future visitors)
I really liked #Bharat Anand's solution, so I wanted to explain how it works (using the images/formulas in the solution as reference):
The calculation in Column I is setup to return a number that will only appear three times, in succession, in Column I; in this way it kind of behaves like a unique identifier, allowing other formulas to reference these values for calculation purposes.
Three times is key for the original poster because they were looking for a range of three cells to be formatted based on a sum of three cells. For example, the formula in Column I can be modified to
=ROUNDDOWN((ROW()-b)/a,0)
where:
a is your desired number of cells to format/sum, and
b is equal to a - 1.
Using the formula in J5 as an example, this SUMIF formula uses I3:I7, which includes two (or b, as setup in my explanation above) rows above and two (b) rows below to decide if I5 equals any of the values found in I3:I7. It's important to include the two rows above and two rows below so that the range overlaps the same three cells to meet the requested requirements.
When I5 finds a match, the formula looks to Column H to sum those rows in H3:H7 where I3:I7 equals I5. In this example, J5, J6, and J7 will each equal 32.
Using the simple conditional formatting formula that was setup, we know that cells in Column E should be highlighted when the corresponding row in Column H is greater than 30. According to the original question, this should be done in ranges that are three (a) rows tall. We already handled for that, so all that was left was to make sure the conditional formatting spanned the data area in Column E.
I'm hoping I don't confuse and/offend anyone with this explanation, but it's how I understand it. I like the proposed solution and explaining it to myself again helps me solidify how it works.
I like to use conditional formatting to provide extra information in my spreadsheets, but I now find myself stuck.
In a spreadsheet of cargo items, I have a column (calculated; it contains a formula) for density. Previously, it just changed text colour, so empty cells didn't stand out. But now that I'm trying to really show up any anomalies with a bright background, I've found that it (or its sibling) highlights all the "empty" cells that don't have calculated values yet.
The formula I'm using is WHERE THE VALUE IS GREATER THAN 10 for the upper out-of-bounds area, and =AND($L2<3,NOT(ISBLANK($L2))) for the lower area. I've also tried using $L2>0 instead of the NOT clause.
The ideal would be changing the upper and lower density limits based on the material it's claimed to be in the description field (column B), but I'm not bothering with that until I get this working.
Is the formula I'm using right, or should I tweak it? Would I be better off just using GREATER THAN 0 and then formatting the right densities blue as =AND($L2<10, $L2>3)?
I think counter-intuitively it is the
WHERE THE VALUE IS GREATER THAN 10
formula that may be doing the damage.
You probably have a formula in column L on the lines of
IF (<cell in previous column is empty> , "" , <some calculation>)
and when the conditional formula compares the result to 10 it actually gives TRUE because a text string is considered to be greater than a number in this context.
I suggest trying two things:-
(1) Change the colour of the WHERE THE VALUE IS GREATER THAN 10 formatting rule to see if the 'empty' cells are highlighted in that colour.
(2) Instead of WHERE THE VALUE IS GREATER THAN 10, use a formula like
=AND(ISNUMBER(L2),L2>10)
this works for me.