How to format rows to color group by like values in column 1 - excel

I have a worksheet that has information like this:
a
a
b
c
c
c
How do I format it so that all of the rows that have a value of a in the first column are one color, then all the rows that have a value of b in the first column are a different color, etc. ?
Edit not from OP to add clarification from comment:
Everything is already sorted alphabetically, and will stay that way, and I want multiple colors.

Create a helper column with a formula like this;
=MOD(IF(A3=A2,0,1)+B2,2)
In this example column A is the column of sorted values to be grouped by, and column B is the helper column. The formula is entered on row 3. Set the first row of the helper column to the value 0 and the others to the formula. This will result in alternating values in the helper column for each group, ie;
a 0
a 0
b 1
c 0
c 0
c 0
d 1
d 1
e 0
You can then set conditional formatting based on the column value. If the value is 1 then highlight the row; if it is 0 do not highlight it. Or use alternating colors or whatever. You can reference any of the articles on the web that describe how to conditional format the entire row based on the value in the column.
IF(A3=A2,0,1) compares the current row (3) and prior row (2) returning a 1 or 0.
MOD( [...] +B2,2) accomplishes the alternation between 0 and 1 when the grouping column value changes.

I think you need a helper column, say B seeded with 1 in row1, and =IF(A1=A2,B1,B1+1) in B2 and copied down to suit. Then formulae of the kind below should suit for conditional formatting:

Related

Finding rows where col A & B match and sum of col C = 0

Hi all,
I am looking for a way to find rows under the following conditions:
Values of column A matches, values of column B matches AND values of column C add to 0.
I've tried sumproduct on conditional formatting without much success.
=SUMPRODUCT(($C$1:$C$9)*($A$1:$A$9=$A1)*($B$1:$B$9=$B1))=0
Perhaps VLOOKUP could be used? Any suggestion would be appreciated!
I'm using two helper columns. You could hide these in your spreadsheet. Col E = colA & colB. Col F has this formula:
SUMIFS(C$1:C$8, E$1:E$8, E1) = 0
This says if the sum of values in col C = 0 where col E matches the current row, TRUE, otherwise FALSE.
Then I added a conditional rule for A1:C8 to highlight in yellow. The rule is
=$F1
This says to highlight the row if the col F is true for that row. I think this will do what you want.
Note that my highlighted results are different than yours. You show 2 rows of 1015 in Col A + B in Col B as highlighted. Why would this be? (50) + 50 + 50 does not = 0? (Thanks to Jerry J for pointing this out.)
Maybe someone more clever than I can figure out how to do it without helper columns. Until then, here is one way to do it:
You need just one helper column - a column that does a running total for each value of A and B. So, put this in D2 and copy it down all the way to D9:
=SUMIFS($C$2:$C2,$A$2:$A2,$A2,$B$2:$B2,$B2)
That will sum all the values above the current cell that have the same A and B. What that does is find where the rows finally sum to zero.
Then you can use this in your conditional formatting:
=COUNTIFS($D2:$D$9,0,$A2:$A$9,$A2,$B2:$B$9,$B2)
That will find the zero below the current cell that has the same A and B. So, it doesn't include cells that have the same A and B that are below the 0.
If you put that second formula in E2 and copy it down all the way to E9 it looks like this:
A
B
C
D
E
Deal
Item
USD
Running Total
Conditional Formatting
1010
A
100
100
1
1015
A
-100
-100
0
1010
A
-99
1
1
1010
A
-1
0
1
1010
B
-100
-100
0
1015
B
-50
-50
1
1015
B
50
0
1
1015
B
50
50
0
If it's not a huge table and you want all rows where A and B match, try this:
=SUMIFS($C$2:$C$9, $A$2:$A$9, A2, $B$2:$B$9, B2) = 0
Or, if you highlight your rectangle and Insert - Table then make a new column with a formula of
=SUMIFS([USD], [Deal], [#Deal], [Item], [#Item]) = 0
then use that column for your conditional formatting formulas and, if you wish, hide the column. That way it's easier to read, you only need to enter the formula once instead of dragging it down the column, and it will store it once instead of once per row.
If it is a huge table then you are going to want to make a pivot table and then use that, because executing this for every row in your raw table will probably be a lot slower than a pivot table would, but using a pivot table is less user-friendly because the changes aren't instant unless you do some VBA to refresh the pivot table anytime something changes.

How to select certain rows in Excel that meet logical criteria of A & B

I have an excel sheet in CSV that has 8 columns A-H and thousands of rows with values 0 or 1 depending on truth value.
I'm looking for the Excel function in which I can select rows where column A and B are true so that I can check another columns probability given A&B. IE P((A&B)|D) (where | means given).
I'm really new to excel and having difficulties finding how to only select rows that meet this criteria.
The following formula entered in I1 will return a 1 if both A1 and B1 are true.
=IF(AND($A1=1,$B1=1),1,0)
Copy it down or autofill to identify all rows where A and B are true.
The $ sign before A and B make the column references absolute meaning if you drag the formula to the right, the references to columns A and B will remain.
Because Excel implicitly interprets 0 = FALSE and 1 (or any other number) = TRUE the formula could be shortened to:
=IF(AND($A1,$B1),1,0)
The probability of C being 1 given that A and B are 1 can be calculated by counting all rows where A, B and C are all 1 and dividing by the number of rows where both A and B are 1:
=COUNTIFS($A:$A,"1",$B:$B,"1",C:C,"1")/COUNTIFS($A:$A,"1",$B:$B,"1")
Again, references to A and B are absolute, while C is relative so you can drag right to get probabilities for columns D to H.
COUNTIFS only counts the rows where all of the criteria are met and allows you to specify up to 127 range/criteria pairs.
EDIT
You could also use:
=AVERAGEIFS(C:C,$A:$A,1,$B:$B,1)
to get the probability.

Counting instances across ranges in columns

I am creating a spreadsheet for my personal use. I need to count the number of times one column's values are equal to an adjacent column's.
Is there any way to do this in Excel without having to modify the formula every time a new row is added?
If you have column A and B now, add column C:
Column A Column B Column C
1 2 =countif(B:B, A1)
2 2
3 1
Then just copy the first value in column C, select the entire column C and paste :)
You will get:
Column C
1
2
0

Sum of multiple columns if they match

I have this table of data:
A B C D E
003B1016 1 003G1016 1 003B1016
003G1015 1 003G1391 2 003G1015
003H0121 4 003H6208 2 003H0121
003H6209 1 003H6209 1 003H6209
I want to sum B+D if A and C are identical , how would i do that?
I have another 32000 rows of data. :) Thanks for the help
Put this in cell E1 and copy down:
=IF(A1=C1,B1+D1,"")
This says - if A = C, then add B+D. Otherwise, return blank "".
EDIT for new requirements
In order to add all amounts from column B where column A matches the current row and from column D where column C matches that row, where the row in column A exists anywhere and the row in column C exists anywhere, do the following formula in E2 and drag down:
=IF(ISERROR(MATCH(A2,A$1:A1)),IF(ISERROR(MATCH(A2,C:C,0)),"",SUMIFS(B:B,A:A,A2)+SUMIFS(D:D,C:C,A2)),"")
This says: look above the current row in column A - have we seen this item before? If no, continue with the formula. If yes, ignore, to avoid double counting. Then, Look at all of column C - does the value in the current row of A occur anywhere in column C? If no, then don't add anything. If yes, Add all items from column B where column A matches the current row, and add all items from column D where column C matches the current row.

Compare in two columns and add value

I have 2 columns looking like this:
Column 1 Column 2
1 x
x 2
2 2
x x
1 2
I want to do two things;
For each row match (row n column 1 = row n column 2) it should mark cell n in column 1 green if there is a match and red if it is not.
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points.
Is this even possible with excel and if so, how is it done?
For the first part of your question:
It should mark cell n in column 1 green if there is a match and red if it is not
You can do this using Conditional Formatting.
Ex:
Assume column A and column B, with the values starting in row 2.
The following conditional formatting would highlight column A values in green if they match the corresponding value in column B in the same row, otherwise red.
Highlight the values in column A, then apply this conditional formatting.
For the second part of your question
It should create a sum cell where each match is worth 1 point, in this case column 1 should result in 2 points
The following array formula will tally all the matches and show you how many there are:
=SUM(IF(A2:A6=B2:B6,1,0))
Assuming again that we are in columns A & B with your sample data.
Remember to commit this formula using Ctrl+Shift+Enter.
Per comment from andy holaday, here is another formula that will work:
=SUMPRODUCT(N(A2:A6=B2:B6))
or
=SUMPRODUCT(--(A2:A6=B2:B6))
These are not CSE formulas so you would not need Ctrl+Shift+Enter to commit them.

Resources