Consider the following data:
I would like to compare each cell in row 1 to the adjacent cell below in row 2, using red for inequality and green for equality. A similar principle applies for rows 3 and 4. I.e., the output should be
The data I have in reality have more rows and columns than in this toy example, so the less manual work that has to be done, the better. The data I have are small enough that I would be fine pointing and clicking for results. I've tried using Conditional Formatting for this, but haven't been able to figure out its formulas.
I would prefer a non-VBA solution if possible.
I don't necessarily need the provided solution to be general, as long as it's clear to me how it can be generalized. I.e., it needs to be obvious how to adjust the solution when the data start at a different row or column, other than cell A1.
The following formula will format all pairs of nonequal cells:
=OFFSET(A1,1-2*MOD(ROW()+1,2),0)<>A1
Create a second rule with <> replaced with = to format the equal cells.
Fill all the cells red then use this rule to turn them Green
=AND(A1<>"",OR(AND(MOD(ROW(A1)-1,2)=0,A1=A2),AND(MOD(ROW(A1)-1,2)=1,A1=INDEX(A:A,ROW(A1)-1))))
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.
I'm trying to conditionally format a column of cells based on whether the combination of two other columns appear in a Table.
Here is a link to the test workbook I am playing with and screenshots below for those that don't like clicking strangers links!
https://1drv.ms/x/s!Al1Kq21dFT1ij4ktFd0mzBniNX00tQ?e=L6aQm4
On the far left is an Excel table ([Table1]) that contains a list of valid combinations of [Category] and [Item]
Columns E&F contain some sample data to test against
Column G is the number of matching combinations I expect to return from a COUNTIFS() function
Column H is simply the same formula compared to 0 so I get a boolean result.
The actual formula to get the result shown in Column H is
=COUNTIFS(Table1[Category],"="&E4, Table1[Item],"="&F4)=0
All the above works as expected.
In Column J is just some literal text with conditional formatting. The condition is simply =H4, again this works as expected.
Now to the problem...
I want to avoid having the helper column (H) so I thought I could just use the same formula that I used in column H, as my condition formula.
So, I tried to use this in the conditional formatting formula dialog.
=COUNTIFS(Table1[Category],"="&E4, Table1[Item],"="&F4)=0
and with parantheses
=(COUNTIFS(Table1[Category],"="&E4, Table1[Item],"="&F4)=0)
Unfortunately, this results in the generic "There's a problem with this formula" error message.
If might be that there are some limitations with conditional formatting formulae that I'm not aware of (I'm no Excel guru, I'm a SQL developer really).
BTW: I need to stick with using a table as my real-world scenario is that there will be several tables, all populated from a database via a separate process with lengths varying from 2 or 3 entries to potentially thousands.
I would appreciate any help, even if it's just to say "You can't do this, you'll need to use your helper column..."
Thanks for looking...
I have searched far and wide but cannot seem to find a question that answers this.
I am trying to highlight/color an entire row in Microsoft Excel for Mac (16.33) based on two different values in two different columns.
This is my current forumla:
=AND(SEARCH("no",INDIRECT("C"&ROW())),SEARCH("yes",INDIRECT("D"&ROW())))
From my understanding, it is searching first in column C for "No", then proceeding to search column D for "yes". Enclosing this in AND() must ensure that both cases are true. If they are not, it returns false and does not apply the formatting.
This formula should return something like this, which works perfectly with the above example in Google Sheets:
Column D contains a yes, but Column C also contains a no, rendering the entire row yellow.
Since conditional formatting works top to bottom, it moves on to the next rule which is:
=SEARCH("yes",INDIRECT("D"&ROW()))
Hence, two "yes" return full green across the row.
I cannot get this to work in Excel with the same exact formulas. I have ensured the correct cell range has been selected for conditional formatting.
Why is such a complex formula needed? The following must work in Excel:
=($C1="N")*($D1="Y") - for yellow
=($C1="Y")*($D1="Y") - for green
Don't know about GoogleSheets
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've got a little helper spreadsheet that I use, and there are some Merged Cells.
Rather than get rid of these, which I know can cause headaches, I was looking for an idea on fixing an issue.
I have a few rows that share a merged cell. When this merged cell is not empty, I want the rows to highlight. Currently, the formula (applied over A1:B4) is =$B1<>"" and then a fill. Works okay for the first row, but not the other three:
I was thinking I could add some more logic, but there's nothing really there for me. It's a pretty simple table. Unfortunately, there's not really a way to say (for rows 2:4), if row 1 is colored, then color this row...(Although I think I've seen clever uses of Named Ranges to do something like that, but I could be mistaken).
So, in A2, what's the conditional format formula "thinking"? Is it going to =$B2<>"", in which case ...what's it looking for as B2? If I select A2, and look at the conditional format rule applied to the current selection, it still shows =$B1<>"".
Thanks for any ideas/tips. It's not a huge deal, so I don't need a VBA solution - just maybe an idea or trick for using CF with merged cells.
Edit: For a more full explanation - the idea is that col. B will have an invoice number and if it's there, make the row a color. I will be repeating this "chart" a bunch, and have some non-grouped companies, who have their own lines. I just don't like the gap of color there in my group and was trying to get it to have a color when the first of the group does.
I usually try to base my CFR's on formulas.
After selecting all of column A and B I created a CF rule with the following.
=AND(LEN($A1), ISNUMBER(MATCH(1E+99, $B$1:$B1)))
The approximate MATCH function simply looks for the last number in the B column. I can see a missing invoice number in a cell like B7 would generate confusion but perhaps you can expand on this for conditions not demonstrated by your examples.
If you want to use "placeholder" instead of blank cells (when there is no invoice), you could try the following formula:
=(LOOKUP(2,1/($B$1:$B1<>""),$B$1:$B1)<>"x")*LEN(A1)
With sample data it looks like this:
When the cell is left blank (no placeholder), column A is highlighted, column B is not.