How to colorize a cell depending on it's value compared to the value of the cell next to it in Excel? - excel

Imagine I have a table like this:
| A | B | C
--------------
1 | 3 | 6 | 5
2 | 5 | 5 | 7
3 | 2 | 3 | 3
I want to:
Compare the values of the cells with the values of the cells above them
Color the background of the cell depending on this comparison
So:
If I compare the value of A2 to A1, 5 > 3, A2 should have a background of red
If I compare the value of A3 to A2, 2 < 5, A3 should have a background of green
If I compare the value of B2 to B1, 5 < 6, B2 should have a background of green
If I compare the value of B3 to B2, 3 < 5, B3 should have a background of green
If I compare the value of C2 to C1, 7 > 5, C2 should have a background of red
If I compare the value of C3 to C2, 3 < 7, C3 should have a background of green
Any ideas on how to do such a thing?
Thanks in advance and best regards,
Meibrah

To color the cells, select the range A2:C3 and choose from the home tab of the ribbon:
Conditional Formatting|Highlight Cell Rules|Greater Than...
with the settings shown, then repeat for Less Than... with Green Text.

In addition to the answer from Lori, I would like to add one more thing.
Instead of using 2 conditional format rules (red + green), just set the background color to your default (e.g. green) and use 1 conditional format rule to turn the cell red.

Related

Use Name in lookup_array

Assuming I have the following data in the sheet.
A
B
1
RED
1
2
GREEN
2
3
BLUE
3
4
COLOR
1
And I define names for B1, B2, B3, and B4 as RED, GREEN, BLUE, and COLOR, respectively.
Next I'm using a formula like below
MATCH(COLOR, {RED, GREEN, BLUE})
but Excel said formula error. I tried MATCH(COLOR, {1, 2, 3}) and it's ok.
So the question is, what's the correct way to use Name in lookup array?

How to change column to header in excel?

a1 | b1 | 0.1
a1 | b2 | 0.2
a2 | b1 | 0.3
a2 | b2 | 0.4
how to transform this table to
xx | a1 | a2
b1 | 0.1 | 0.3
b2 | 0.2 | 0.4
Make use of Pivot tables. Enter Column A as Column labels, Column B as Row Labels and Column C as Values. If values are not sum by default, change it to Sum.
Output:
You can remove the headers deselecting the Field Headers in Options tab.
You can also hide the grand totals by clicking on Options under the same tab. (Located at the left corner of the screen).
If you don't want Grand Total and other..., you can use Index:
Create a New Sheet with your Header xx, a1, a2
Copy column B b1, b2,...to the new sheet under xx
select the Data b1, b2,... in the new sheet
Remove Duplicates
Distinct and unique values will remain
Under a1 write the following formula:
=IFERROR(INDEX(Sheet1!$C$1:$C$4,MATCH(B$1&$A2,Sheet1!$A$1:$A$4&Sheet1!$B$1:$B$4,0)),"")
Array Formula press Ctrl+Shift+Enter at the same time instead of Enter
and drag it in the same row and down in columns
Change A1:A4, B1:B4 and C1:C4 to correspond your last row of Data but keep $ for fixed references

Get the count of not null values before the cell

As shown in the image in Col2 I need to get the count of not null values in the Col1 before the cell.
For cell B2 there is only one value A hence 1.
For cell B4 it should be 2 as there are 2 values A & C.
Same way for B5, 3 (A,C,D)
Data:
A B
1 Col1 Col2
2 A 1
3
4 C 2
5 D 3
6
7 F 4
I have tried:
B1 Cell = COUNTA(A2:A2)
B2 Cell = COUNTA(A2:A3)
B3 Cell = COUNTA(A2:A4)
However I cannot drag this formula as it will change the cell reference.
Can anyone suggest any way to get this done in a single formula which can be applied to all the cells through out the column.
Try this:
=IF(A2<>"",COUNTA($A$2:A2),"")

Sum fields in a column if there is an entry in a corresponding row in another column

Assume the following data:
| A B C
--+------------------------
1 | 2 3 5
2 | 2 3
3 | 4 4
4 | 2 3
5 | 5 6
In cell A6, I want Excel to add cells C1, C2, C3 on the basis that A1, A2 and A3 have data in. Similarly, I want B6 to add together C1, C4 and C5 because B1, B4 and B5 have data.
Can someone help?
In A6 enter:
=SUMPRODUCT(($C1:$C5)*(A1:A5<>""))
and then copy to B6:
A simple SUMIF formula will work
=SUMIF(A$1:A$5,"<>",$C$1:$C$5)
Place that formula is cell A6 and then copy it to B6.
You can create another column, e.g. AValue, with the formula =IF(ISBLANK(A1),0,A1) in it. This will return 0 if the cell in A in the corresponding line is empty, or the value from the cell in A otherwise.
Then you can just sum up the values of the new column.

Excel: Given a cell in column B as input, how could I find out the lowest cell of A which B > A?

I have an excel sheet, which value of column A >= B in the same row.
I would like to know given a cell in column B, how could I find out the lowest cell of A which B > A? (It should return a cell address but not the value)
For example, the following shows cells from A1 to B7 in a sheet:
A B
------
1 | 1 1
2 | 3 2
3 | 5 3
4 | 7 4
5 | 9 5
6 | 10 6
7 | 15 10
Now I would like to input B6, then it should return A3 (since 6 > 5)
Another example, if I input B7, then it should return A5 (since 10 > 9)
Is there any approach (or similar approach) by using excel formula? Or should I use other methods?
If your input value is in cell E1, and your return value is in cell E2 (as shown in below image), then you can use this formula in cell E2:
=IF(E1="","",INDEX(A1:A7,MAX(1,MATCH(TRUE,INDEX(A1:A7>=E1,),0)-1)))
Input Cell E1 (enter the address from column B here)
F1: =ADDRESS(LOOKUP(2,1/(INDIRECT(E1)>ColA),ROW(ColA)),1,4)
Given your data, if you enter B6 in E1, A3 will show in F1

Resources