Excel highlight duplicates in 2 columns, ignoring same row - excel

I have 2 non adjacent text columns that I wish to compare. There may be duplicates in both columns but if they are not on the same row I need them to be highlighted in both columns. In the example below, Barry and Larry would both be highlighted in Columns A & C.
| Col A. | Col B. | Col C.
Row1.| Harry | London | Harry
Row2.| Barry | Paris | Larry
Row3.| Larry | New York | Barry
Row4.| Gary | Munich | Tom
If the same names are not aligned in the same row I would then cut and paste the offenders to resolve the problem. In this case the Barry in column C would be cut and inserted into row 2, forcing Larry down into row 3. Nothing would then be highlighted.
I guess it is a conditional formatting problem but I can't get a formula to work. I would appreciate some ideas.

So if I am understanding you correctly, you want to:
1) Find duplicates and highlight them
2) Move the offenders
Is there some reason this needs to be two parts? For moving the offenders I would run 2 loops, one to loop through the cells in column A, for each cell in column A I would loop through column C until I find the match, cut it, and paste it into the range that is two columns over from the current cell you are comparing in the first loop. you can use a range offset to find the right place to paste the name in column C.
Arrays would do this more quickly, so if you have a large number of records it would be worth looking in to.
You can use a dictionary object to accomplish both steps more easily, you can use dict.exists(value) to determine if a match exists and use those addresses for formatting, a quick google will help you with how to use them.
Honestly this seems like a homework problems so that's as far as I will go.

Related

Excel - Tell if Column A a third of Column B

I'm drawing a blank how to do what I think is a simple formula with a color change.
I have two columns see below
A | B
------
3 | 9
25| 10
I want to change the value in Column A is a third of Column B so the first row the 3 should be highlighted in red where as the second row just be left alone. I have tried MOD, IF statements to keep it simple but just tripping over myself.
Any pointers to functions or a start of a formula at a high level like IF(column b / column a) will lead me to my answer be appreciated.
Thank you for your time.

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

Excel Substitute a substring in cell (sheet A) by the corresponding string in "lookup" (sheet B)

How to do this in MS Excel 15.4
I want to process Column A to become Column B
Column A | Column B
----------------------------------------------------------------------
one, 1, two, 2, three, 3 | one apple, two bananas, three strawberries
one, 1, four, 4 | one apple, four oranges
.......................
... many other rows ...
.......................
two, 2, four, 4, three, 3 | two bananas, four oranges, three strawberries
The Column A can have n matching substrings in the lookup sheet.
I have another sheet (lookup table) with what to substitute the text in Column A with
Match col | Replace col
----------------------------
one, 1 | one apple
two, 2 | two bananas
three, 3 | three strawberries
four, 4 | four oranges
... and many more ...
I want to replace all the substrings found in Column A with the Replace col value of the lookup table
It looks like I may be able to combine VLOOKUP with SUBSTITUTE, but I am struggling with it
To do it in indivdual cells;
=IFERROR(VLOOKUP(TRIM(SUBSTITUTE(MID(SUBSTITUTE($A1,",",REPT(" ",999)),(COLUMN(A:A)-1)*2*999+1,2*999),REPT(" ",999),",")),Sheet2!$A:$B,2,FALSE),"")
If you have a subscription to Office 3651 excel you can use this array formula to put it all in one cell:
=TEXTJOIN(",",TRUE,IFERROR(LOOKUP(TRIM(SUBSTITUTE(MID(SUBSTITUTE($A1,",",REPT(" ",999)),(ROW(INDIRECT("1:" & INT((LEN($A1)-LEN(SUBSTITUTE($A1,",","")))/2)+1))-1)*2*999+1,2*999),REPT(" ",999),",")),Sheet2!A:A,Sheet2!B:B),""))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
On caveat is that the reference data must be sorted on the lookup column:
1 If you do not have Office 365 but want to use this formula you can place the code from my answer HERE that will mimic the TEXTJOIN() in a module attached to the worksheet. Then use the formula as described above
I have a rather clunky solution, but it'll work for you if you don't mind taking perhaps a few extra steps. (No VBA required).
With your original data, highlight all of it and do Text to Columns with a comma delimiter. Set the destination to wherever you like. I chose the column just right of it (so, B2):
So now you have it all split up.
I put the VLOOKUP() table in "Sheet2":
And back on Sheet1, in I2, I used this formula:
=IFERROR(VLOOKUP(TRIM(B2)&", "&TRIM(C2),Sheet2!$A$1:$B$4,2,FALSE),"")
And drag right. You'll have some empty columns which you can hide/Delete, then copy all the data.

Pick Out Email From a Row

I have over 100k rows similar to:
Joe | 123 | email#domain.com
Bob | 456
Ben | 567 | Denver | email#email.com
The emails could be at any point/cell in that row and some cells have # in them.
How could I get the following output:
Joe | email#domain.com
Bob |
Ben | email#email.com
or maybe just tag the email address onto the end of the row and then hide the other columns?
I've tried various bits and pieces but am getting nowhere fast.
Now that I know you can have it in every column, Add a column left of column A. In your example you then have B1="Joe", etc.
Then put this formula in A1:
=IFERROR(OFFSET(A1,0,SUM(IFERROR(IF(FIND("#",$B1:$O1)>0,1,0),0)*COLUMN($B1:$O1))-1),"")
Adjust the range $B1:$O1 to match your needs. I suggest you make it as tight as possible because array formulas are resource-intensive.
========================
If the email addresses were always in the last column of a given row, and if there weren't any blanks in the row until the last value, you could just do that:
First, Add a column left of column A. In your example you then have B1="Joe", etc.
Then, put this formula in cell A1
=OFFSET(A1,0,COUNTA($B1:$XFD1))
and drag and drop it on all your rows. (I'm using Excel 2010, hence XFD in the above formula. Adjust as you see fit, just make sure you use a range that covers the maximum number of columns for your dataset)
A bit of fun really.
Embolden the names and for the rest Replace All # without formatting with # and Font style Bold. Copy into Word, Select All, Find what: * with Font Not Bold, Use wildcards and replace with nothing. Copy back into Excel and Go To Special, Blanks. Right click on one of selection and Deleteā€¦, Shift cells left.

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