I have a Excel 2010 Sheet which contains some values.
I want to achieve the following in a specific Cell:
If the User changes the Value more than 50% make it red, more than 25% make it yellow, below make it green.
I tried achieving this with conditional formatting (3-color-scale) using a copy of that value that cannot be changed as a reference using the following formula for the red paint:
=ABS(Y10-BV10)/(BV10)>0,5
(where Y10 is the value that can be changed and BV10 contains the same value as a reference)
When trying to do this I receive the Error:
You cannot use relative references in Conditional Formatting criteria
for color scales, data bars and icon sets
Any other way to achieve this?
(I create the file myself by OpenXML and so could use fixed values in the formula instead but that seems to be a very dirty solution as this formatting should work for a few hundred cells)
Rather than using a colour bar, do the formatting manually using the formula you have used to change the colour. You'll just need to have 2 formats in order. The first saying if > 50%, the next being greater than 25%
In a new conditional formatting rule, go to Use a formula to determine which cells to format option - http://office.microsoft.com/en-gb/excel-help/use-a-formula-to-apply-conditional-formatting-HA102809768.aspx
you will need separate formula for each color though - to achieve the desired effect, make sure the rules are either mutually exclusive or else in correct order (in Manage Rules... dialog - the most general rule should be on top if you don't check "Stop if True", but if you check those checkboxes then the most specific rule should be on top)
Related
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'm trying to set conditional formatting in a specific group of cells J9:N12 with a locked cell I9 (110). In Cells J9:N12 I need the conditional formatting to set 1,2,7,8,13,14 as Black Fill w/ White Text, 3,4,9,10,15,16 as Red Fill w/ Black Text, 5,6,11,12,17,18 as Blue Fill w/ White Text. Then if I Change (I9) to 277 the Fills would change to reflect Brown/Orange/Yellow in place of the Black/Red/Blue.
Yes, I can Conditional Format the cells I need based on the information set in cell (I9) 110 or 277.
The series of numbers I need to format is greater than 120. I cannot set Conditional Formatting for each specific number needed. Minimallistically I need to be able to set Conditional Formatting to around 150-160 numbers.
I don't know if I need to utilize VBA or if Conditional Formatting is the way to go.
You could use conditional formatting for this. I'd be tempted to put the number series in an array and test for a find in the array using MATCH. This way, you'd only need as many conditional formatting rules as there are number series.
I'm not certain, but I believe you can't write an array directly into a conditional format rule, but you could refer to it from something like a range name. In any event, a range name would be easier to manage if you needed to change any of the number series.
For example, in the black/brown case, you could create a range name (Formulas->Define Name), called black-brown, and in the Refers To window, have the formula:
={1,2,7,8,13,14}
Then your conditional formatting rule would be something like:
=AND($I$9=110,NOT(ISNA(MATCH(B2,black_brown,0))))
Note my cell to be tested is in B2 - change that to whatever you need.
You'd just add rules for each of your number series cases, as shown below:
Is it possible to create a border around cells that have the same value in column B like in the picture below (using conditional formatting)? Or would this have to be done using VBA?
You sure can using multiple conditional formatting rules.
In your example it's very easy to manually just add the outside borders (assuming this range won't change).
Then select the range B2:D14 and add a conditional formatting rule through formula:
=COUNTIF($B$2:$B2,$B2)=1
Make sure to apply the top border formatting and press OK.
That's it...
If you want your range to change you can use the following three conditions:
(note that for this to work, the first row needs to either be blank or be a header)
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 have been trying to change the color of certain cells on my WS that fall outside of an acceptable range. The statement I've been trying to use is,
IF(OR('cell'>1.3,'cell'<2.5),'turn red','do nothing')
In english, "If a cell is less than 1.3 or greater than 2.5 turn red, else do nothing." I cannot find a resource that guides me to how I can get the cells to change colors. I also have been unsuccessful in creating a statement in the Conditional Formatting tab that satisfies my goal. I feel this should be simple, but for some reason cannot figure it out. Does anyone know if this is possible, and if so how to do it?
EDIT: Also, I have different ranges based on another cell on the spreadsheet. I need this also taken into consideration
Select the columns that you want to format
Click Conditional format --> new rule
Select "Use a formula to determine which cells to format"
In the formula bar enter the formula =AND(A1>1.3,A1<2.5)
Choose the fill color as red and press OK
am confused with your formula and your english version. If its the other way, then use the formula =OR(A1<1.3,A1>2.5)