Conditional Formatting - Highlight every cell that doesn't match in two rows, then move to next two rows - excel-formula

I have two worksheets that I'm trying to compare and then highlight every cell that is different between the two. I've cut/pasted all the rows into one worksheet and highlighted the ones from the original spreadsheet. It's easy visually to see the differences, but I'm trying to use conditional formatting to highlight just the rows that are different. I only want to check the first two rows for differences, then move to the next two rows checking for differences, then move to the next two rows.
Worksheet1
1 Brown, Jean 100 Main St Richmond VA This is a long note about this contact. 12/14/2014 Yes
Worksheet2
1 Brown, Jean S. 101 Main St Richmond VA This is a long note about this contact. 12/14/2015 No
Worksheet1
2 Tomas, Bill 2500 Sky Cir Charlottesville CA This is a long note about this contact. 12/15/2014 No
Worksheet2
2 Tomas, Bill 2500 Sky Cir Charlottesville VA This is a long note about this contact. I added some to it. 12/15/2014 No
Every time I try to do it, it just checks each cell against the previous cell. I just want to compare the first two rows, then compare the next two rows, etc. I need to attach this to an affidavit showing what changes I made to the worksheet, and I don't want to rely on my eyeballing each row and manually highlighting the differences. Our IT group tried a special Compare software, but the result was a very difficult to read PDF file with lots of little pop-up comments that you have to hover over to see the differences.

You can achieve what you need with conditional formatting.
Assume your data is as follows:
A B C D E F
1 Brown, Jean 100 Main St Richmond VA This is a long note 12/14/2014 YES
2 Brown, Jean 101 Main St Richmond VA This is a long note 12/14/2015 NO
3 Tomas, Bill 2500 Shy Cir Charlotte CA This is a long note 12/15/2014 NO
4 Tomas, Bill 2500 Shy Cir Charlotte CA This is a new note 12/15/2014 NO
For each column you need to set a conditional format formula. Example for Column A:
Open Conditional Formatting
Select New Rule
Select Use a formula to determine which cells to format
Add the following formula
=AND(MOD(ROW(),2)=0,A1<>OFFSET(A1,-1,0))
Now apply for format you want to use as a highlight e..g red color
Note: You need to add the formula for each column separately and update the column references. For example, column B formula would be:
=AND(MOD(ROW(),2)=0,B1<>OFFSET(B1,-1,0))
The trick with this formula is the MOD(ROW(),2 = 0. It looks at even rows only (i.e. 2, 4, 6 etc..) and then compares to the previous row. This is important to know depending on how your data is set up in your spreadsheet i.e. in my example I assume your first row is in row 1 and so it is every even row I am comparing to the previous row

Related

Excel: Turn duplicates in a link into blank cells

I have a list of names that includes duplicates (all in Column A of my worksheet). What I am trying to do is convert the duplicates into blank cells. I do need to keep the values in the rows where column A ends up with blanks. In the example below, I demonstrate what I currently have in my list and the second table demonstrates what I need the result to look like. The names Mike, Bill and Jim are the duplicates that are converted to blanks, but next to those blanks I still have the values I need (Xs in columns 1 and 2). The reason I want to get blanks is because I will filter those blanks out and remove them from a master table I am working.
I used the available tools in excel to identify duplicates (conditional formatting), and then "remove duplicates" but when I do that Mike, Bill, and Jim are deleted and all of my data shifts around and it doesn't work for what I am trying to do.
I am wondering if there is a formula that I can possibly use? or perhaps a macro/vba? Any help would be greatly appreciated! Thank you.
name
column_1
column_2
bill
jim
mike
sandra
mike
x
bill
x
x
dave
x
x
jim
x
name
column_1
column_2
bill
jim
mike
sandra
x
x
x
dave
x
x
x
I have your data starting in Column A1 with a Header (called Name in A1). Then I use the formula- in Column B2 =COUNTIF($A$2:A2,A2) * kindly note, that the 1st part of the range is 'Anchored' with the absolute reference aka the '$' sign. this will start at the top of the range and when copied down will include the 1st cell (with Bill in it).
so in column B, it looks to Col A for how many times that name occurs. I would filter on Column B and show all cells NOT equal to 1 (uncheck the filter box for '1') and remove the rows and you will be left with the 1st occurance of the name.
when you delete, delete entire rows in filtered data (this will remove the spaces
Create a helper column and put the following formula into all of its cells:
=COUNTIF(A$2:A2;A2)-1
All entries with a duplicate (in a row above it) will contain a value > 0

Search for duplicate text string in two columns and highlight, excel

I'm looking for a way to search and highlight duplicate text strings in two different columns in Excel; this means that the cell content doesn't have to be identical, instead of that is what I need is that if the content of column A is somehow contained in any cell of column B, both cells get highlighted.
For example, let's say that I have two columns, one named "Patient" and another one called "Couples". So, what I would need is to make a comparison between both columns, and if one of the patient's names is within a couple, both cells get highlighted:
Column A. Patient name | Column B. Couple name
John Smith | Adriana Lewis - Mark Rutte
Peter Brown | Giaccomo Down - Rosy Lawn
Jerry Goldsmith | Bob Loewe - Gigi Pink
Ewan Thompson | Sonia Farrel - John Smith
In this example, the content of A2 ("John Smith") is also contained in B5 ("Sonia Farrel - John Smith"), so that I would need that both A2 and B5 get highlighted. Also, both columns don`t have the same range, one is shorter than the other, since there are more names than couples; and it can happen that two names in different cell are contained in a single couple, so that all three cells should get highlighted.
I have tried everything, with no success... please help!
Multiple ways to do this but here's one option with conditional formatting.
Rule applied to data in column A, using COUNTIF and wildcards.
=COUNTIF($B$2:$B$5,"*"&A2&"*")>0
Rule applied to data in column B, using ISNUMBER, SEARCH and SUMPRODUCT.
=SUMPRODUCT(--ISNUMBER(SEARCH($A$2:$A$5,B2)))>0

Pick multiple values from list and ignore empty cells

I have the following Excel spreadsheet:
A B C D E F G
1 USER1 USER2 MICHAEL SANDRA JAMES CAITLIN
2 Product A Michael James Michael James
3 Product B Sandra Caitlin Sandra Caitlin
4 Product C James Caitlin James Caitlin
5 Product D Michael Sandra Michael Sandra
In Columns D:G 4 users of a product are listed. If a product is used by a User his/her name appears in Cells D2:G5. If he/she does not use the product the cell remains empty.
In Columns B:C I want to achieve now that the emtpy cells are eliminated and the maximum 2 Users are listed.
Do you know any formula that can go through the Cells D2:G5 to pick the 2 Users and show them in Columns B:C?
I don't know of any quick formula that you can use.
You are probably best off using VBA. You could write something compact and concise in there. VBA is definitely the way to go if your matrix is going to grow in size.
However, if you insist on doing it in Excel with available formulas, AND the matrix remains relatively small, here is one way to do it:
You will need column H and I for "Mask" information. You can hide these columns in the finished worksheet.
A B C D E F G H I
1 USER1 USER2 MICHAEL SANDRA JAMES CAITLIN MASK1 MASK2
2 Product A Michael James Michael James 1010 10
3 Product B Sandra Caitlin Sandra Caitlin 101 1
4 Product C James Caitlin James Caitlin 11 1
5 Product D Michael Sandra Michael Sandra 1100 100
In cell H2, You can create the first Mask:
=IF(D2 <> "",1000,0)+IF(E2 <> "",100,0)+IF(F2 <> "",10,0)+IF(G2 <> "",1,0)
This is a positional Mask which puts a 1 in each numeral column where data exists.
In cell B2 for USER1, you can put the nested IF formula:
=IF(H2>=1000,D2,IF(H2>=100,E2,IF(H2>=10,F2,IF(H2>=1,G2,""))))
This uses the Mask to find the first occurrence of data and place it in the USER1 column.
Finding the second user is a little more tricky. But all we have to do is create a second Mask in column I. In cell I2 you can use this formula:
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
Let me break that formula down for you. We want to convert the first Mask in H2 to text so that we can trim off the first character (which corresponds to USER1) because, we don't need USER1 data anymore. Using TEXT(H2,0)
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^
But to do a right trim that removes the right most character, we need the length of the same text string minus 1. LEN(TEXT(H2,0))-1
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^
Using those in a RIGHT function gives us our new Mask which removes USER1.
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But we can't do math on a text string, so we have to convert it back to a number using the Value function.
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That's our new Second Mask that we can use to find USER2. However, we need to test for error values as well. If all the cells are blank, it will have an error since you can't have a length of 0 in a Right function. So we need to test if the length of the text is greater than 1. LEN(TEXT(H2,0))>1
=IF(LEN(TEXT(H2,0))>1,VALUE(RIGHT(TEXT(H2,0),LEN(TEXT(H2,0))-1)),0)
^^^^^^^^^^^^^^^^^
Encase that all in an If statement and you now have your new Mask for USER2.
Now it's a simple nested IF formula for cell C2 by using the Mask in cell I2:
=IF(I2>=100,E2,IF(I2>=10,F2,IF(I2>=1,G2,"")))
We were able the toss out the test for 1000 since we know that would have been caught for USER1.
Now just copy the cells B2, C2, H2, and I2 down three more rows and all of your data will appear.
You can hide columns H and I if you'd like.
So, all in all, it's not that difficult (if your matrix remains small). There are only 4 formulas needed to make this work. And they are only of moderate complexity.
But once again, if your matrix is eventually going to grow in size, it will definitely be better to write this all in VBA.
Hope this helped. :)
It is possible without a formula though might be a bit tedious without VBA or similar (though not tagged that way):
Insert enough extra columns between C and D to be able to copy all of D:G into C.
Copy what was D:G into C and move what was the content of D:G out of the way (to other rows or other sheet/book).
Select the populated rows in C:F (or equivalent), HOME > Editing > Find & Select, Go To Special..., Blanks (only) OK.
Right click one of the selected cells and Delete..., Shift Cells left, OK.
Copy what was D:G back to E2.
The chosen two will be those furthest to the left.

Highlight duplicates, ignoring same row

I have a worksheet containing names in 2 dimensions. Each row represents a general location, every other column represents a specific slot in that location (each location has the same number of available slots), alternating with a parameter belonging to that name. There is a name in each cell. Here's a simplified version to show what my data looks like:
Location 0 ( ) 1 ( ) 2 ( ) 3 ( )
Garden Tim 3 Pete 1 Oscar 1 Lucy 2
Room1 Lucy 1 Tim 1 Lucy 5 Anna 1
Kitchen Frank 1 Frank 2 Frank 1 Lucy 1
What I want to achieve is to highlight (using conditional formatting, I'm open to alternative methods though) each entry that also appears in another row. So basically it should highlight duplicates, but ignore duplicates in the same row. The first row and column are to be excluded from the operation (no big deal, I just don't select them), as are the parameter columns (this is a big deal, as this pretty much breaks everything I've tried including the first answers given). I have access to the entire meaningful data area (all cells containing names) by the name "entries" and all meaningful entries in a given row by the name "row".
In my example above, all Tim and Lucy entries should be highlighted because they have duplicates in other rows. Pete, Oscar and Anna are unique, so they're not highlighted. Frank, while having duplicates, only has them in the same row, no other row contains Frank, so he should not be highlighted. Excel's own highlight duplicates would highlight Frank, while handling all the others correctly.
How can I modify the conditional formatting's behaviour to ignore duplicates in the same row?
The following formula (thanks to #Dave) resulted in a #VALUE! error:
=(COUNTIF(entries;B2)-COUNTIF(row;B2))>0
or you could just do (no need for an IF() when used in Conditional Formatting Formula box:
=COUNTIF($B$2:$I$4;$B2)>COUNTIF($B2:$I2;$B2)
This single formula should prevent the parameters from being highlighted
select B2:I2 and
put this (exactly) in the conditional formatting box: =AND(NOT(ISNUMBER(B2));COUNTIF($B$2:$I$4;B2)>COUNTIF($B2:$I2;B2))
Something like this:
=(COUNTIF($B$2:$E$4,B2)-COUNTIF($B2:$E2,B2))>0
The first countif counts all instances in the range, the second one subtracts the count of entries in the row. If there are more instances in the entire range than in the row it returns true

Add cell string to another cell if 2 cells are the same for 2 rows

I'm trying to make a macro that will go through a spreadsheet, and based on the first and last name being the same for 2 rows, add the contents of an ethnicity column to the first row.
eg.
FirstN|LastN |Ethnicity |ID |
Sally |Smith |Caucasian |55555 |
Sally |Smith |Native American | |
Sally |Smith |Black/African American | |
(after the macro runs)
Sally |Smith |Caucasian/Native American/Black/African American|55555 |
Any suggestions on how to do this? I read several different methods for VBA but have gotten confused as to what way would work to create this macro.
EDIT
There may be more than 2 rows that need to be combined, and the lower row(s) need to be deleted or removed some how.
If you can use a formula, then you can do those:
Couple of assumptions I'm making:
Sally is in cell A2 (there are headers in row 1).
No person has more than 2 ethnicities.
Now, for the steps:
Put a filter and sort by name and surname. This provides for any person having their names separated. (i.e. if there is a 'Sally Smith' at the top, there are no more 'Sally Smith' somewhere down in the sheet after different people).
In column D, put the formula =if(and(A2=A3,B2=B3),C2&"/"&C3,"")
Extend the filter to column D and filter out all the blanks.
That is does is it sees whether the names cells A2 and A3 are equal (names are the same), and whether the cells B2 and B3 are equal (surnames are the same).
If both are true, it's the same person, so we concatenate (using & is another way to concatenate besides using concatenate()) the two ethnicities.
Otherwise, if either the name, or username, or both are different, leave as blank.
To delete the redundant rows altogether, copy/paste values on column D, filter on the blank cells in column D and delete. Sort afterwards.
EDIT: As per edit of question:
The new steps:
Put a filter and sort by name and surname. (already explained above)
In column E, put the formula =IF(AND(A1=A2,B1=B2),E1&"/"&C2,C2) (I changed the formula to adapt to the new method)
In column F, put the formula =if(and(A1=A2,B1=B2),F1+1,1)
In column G, put the formula =if(F3<F2,1,0)
In column H, put the formula =if(and(D2="",A1=A2,B1=B2),H1,D2) (this takes the ID wherever it goes).
Put the formulae as from row 2. What step 3 does is putting an incremental number for the people with same name.
What step 4 does is checking for when the column F goes back to 1. This will identify your 'final rows to be kept'.
Here's my output from those formulae:
The green rows are what you keep (notice that there is 1 in column G that allows you to quickly spot them), and the columns A, B, C, E and H are the columns you keep in the final sheet. Don't forget to copy/paste values once you are done with the formulae and before deleting rows!
If first Sally is in A1 then =IF(AND(A1=A2,B1=B2),C1&"/"&C2,"")copied down as appropriate might suit. Assumes where not the same a blank ("") is preferred to repetition of the C value.

Resources