lets say I have a xls sheet with just one column which has the following content:
1
2
3
3
4
5
5
6
You see there are some cells with equal content.
Now I want Excel to format (e.g. background) all cells which are there twice.
I would say that conditional formatting is the right way but there I always have to enter a certain cell.
Is there any possibility to do this?
Best,
Elias
I do this routinely. Start at the second cell and select the rest. Choose Conditional Formatting, as you thought, select VALUE IS EQUAL TO, and click the cell above (let's call it A1). Here's the trick: it will enter this as an absolute reference - $A$1 - but you need to strip out the dollar signs, so it is relative. Now (of course) assign a background color, or whatever style you want, and the first cell in any sequence of identical values will have normal formatting, but subsequent cells will have the style you choose.
This isn't exactly what you've asked for - the first 3, for instance, will still have normal formatting - and I'm not sure I know a way to get all the duplicated cells, including the first, styled differently. But it's a start...
Select A1:A8 and enter this conditional format - Formula Is
=COUNTIF($A:$A,A1)>1
and set a format. It will format anything in column that appears more than 1 time.
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'm trying to have a cell becoming highlighted if it satisfies two criteria.
I would like the cells below each Staff column to be purple if its both the same as the version# and contains *.
I've managed to highlight cells containing the * by using "highlight if cells contain" ~* but I can't get it to do both.
I've tried
=AND(L2=$J2,"~*")
=AND($J2,"~*")
=IF(AND(L2=$J2,"~*"))
(Version# is column J, Staff 1 is column L)
Answer by BigBen
If the Staff # contains an asterisk, will it always immediately follow the version #? If so you could just do
=L2=$J2&"*"
Seeing what I think you want, the main issue is the asterisk. When you enter a number in a cell and also enter a non-numerical character the cell automatically becomes formatted as TEXT. It is possible to extract the numerical value with a formula, but handling what you want is much easier if you separate the number from the asterisk. In my included example (You should be able to open it in a new tab on your browser) created narrow columns after each 'staff#' column to accept the asterisk entry.
This done, enter the three conditional formats as shown (in C2 in the example). You then copy the C2 cell into each of the cells under the Staff# columns. That produced the results shown which I think is what you want. Changing entries will produce the proper formatting results for that cell.
it´s my first post.
I have different tables.
for example: range(F9:M16), range(F24:M31) etc.
in A1 I define the row and in B1 I define the column.
example: G3 = 3, H3 = 4
With this information I will create a red bold border in H12.
because in range(F9:M16) is H12 the row 3 and column 4. and in the other ranges are diferent.
so i need a makro, because I do it every time manually.
thanks for your help.
regards
thomas
If you want to highlight cells according to specific conditions, Conditional Formatting is usually the way to go; you can do a lot of very neat things automatically without resorting to a macro.
In this case:
select the range on which you want to apply your format (F9:M16)
create a new conditional formatting, select "Use a formula to determine which cells to format
as a formula, use: =AND(COLUMN(F9)-COLUMN($F$9)=$G$3;ROW(F9)-ROW($F$9)=$H$3)
define your format (red border or whatever else you fancy)
Repeat for all your tables, adapting the references each time. Now the highlighted cell changes according to what you put in $G$3 and $H$3 without you having to do anything.
What this does is, for each cell, get its relative column/row references by calculating the difference from the row/column of the cell being checked (F9 being relativ,e it will change for each cell) and the row/column of the upper-left cell of the range ($F$9 will NOT change) - resulting in a range starting from 0, but since you use 0 in your table, that's fine. If not, you'll need to adjust by adding a constant. If both (the AND part) these indexes match, you apply the formatting. Note that if you use an OR, the whole row and whole column will be highlighted.
thanks for your answer.
Correct, I had already used the Conditional Formatting, but for this case it isn´t optimal.
Because I have no oppurtunities to change the thickness of the borders. I would like to have a red, thick border.
thanks for your help.
regards
thomas
Suppose I have this content 8.XY in an Excel cell. I would like to add leading zeros such that it looks like 0008.XY. The converted value will always have 4 digits in front.
Other examples are 78.XY becomes 0078.XY. 188.XY becomes 0188.XY. 1123.XY remains 1123.XY. What Excel formula can I use to achieve this?
Assuming your string to be checked is in cell A1, use
=IFERROR(REPT("0",5-FIND(".",A1)),"")&A1
The IFERROR function is used in case your string has more than 4 characters before the period.
The following formula will do what you want by essentially converting your data to a string, where I have used G2 as the cell with your data in. =IF(FIND(".",G2,1)-1=4,G2,IF(FIND(".",G2,1)-1=3,"0"&G2,IF(FIND(".",G2,1)-1=2,"00"&G2,IF(FIND(".",G2,1)-1=1,"000"&G2,"0000"&G2))))
There are apparently more than one way to crack an egg, as evidenced by the number of working answers.
Another way, again assuming your string to be checked is in cell A1 could be to use the CHOOSE function which I prefer over nested IFs because of its clarity.
=IFERROR(CHOOSE(FIND(".",A1),"0000","000","00","0",""),"")&A1
IFERROR is used in case the string has five or more characters before the period.
CHOOSE selects a value or action to perform based in the index number in the first function parameter.
Based on your statement that the number will always have 4 digits in front of the decimal.
=right("000"&A1,7)
The above also assumes you will only have 2 characters after the decimal point.
If you have the possibility of having more than 4 character in front of the decimal point, you could use the following:
=if(FIND(".",A1)<5,right("000"&A1,7),A1)
Again this assumes only 2 characters after the decimal point.
IF you are just interested in displaying your integer with leading 0 and a trailing .XY, then you could format your cells to display that. In order to achieve this follow these steps.
1) Select the a cell or the range of cells with the data you want changed.
2) While those cell are selected, go to the "HOME" ribbon and select the drop down menu adjacent to GENERAL.
3) From the menu that is displayed, select "More Number Formats".
4) In the window that comes up select "Custom" in the Category window.
5) In in the Format Bar enter: 0000".XY" .
6) Copy cell formatting to other cells as required.
Another Method to Achieve
Assuming your strings starts with A1 and A2 and so on (Please refer the snap below).
Apply the below formula in B1 and drag down
=REPT("0",4-(SEARCH(".",A1)-1))&MID(A1,SEARCH(".",A1)-(SEARCH(".",A1)-1),LEN(A1))