Solved

Compare Two Columns to another Two Columns and Return "X" to another Column

Posted on 2011-09-14
12
274 Views
Last Modified: 2012-06-27
Hi

I need to compare column H & I to D & E and if there is a match to place an "X" in column G.
Sounds simple enough but can't seem to get it.

Thanks in advance,
Bob CompareColumns.xls
0
Comment
Question by:schumarg
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 5

Expert Comment

by:slycoder
ID: 36537992
Your sample doesn't have any pair that matches but this should work:

=IF(UPPER(H9)&UPPER(I9)=UPPER(D9)&UPPER(E9),"X","")

(tested with row 9)
D9=Aikenhead
E9=Jim
0
 
LVL 12

Expert Comment

by:viralypatel
ID: 36537996
not clear ...
Two clarifications needed:
Do you mean if the combination in D&E exists in H&i you want to place an X in column G?
Do the values in H&I need to be in upper case?
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 36538006
The suggested formula in cell G2 (copied down) would be:
=IF((H3&I3)=(D3&E3),"X","")

This will work, regardless of casing (upper, lower, proper), but not if there are spaces before or after.  Also, it would not match if the name has a middle initial (ex. "GARY W.")

There are no matches in the example workbook.

If, however, you are looking for ANY possible match (say, across two different rows), it will be considerably more difficult.  Also, your data set has variations on names (ex. "Jim" vs "James" Aikenhead).
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 27

Expert Comment

by:Glenn Ray
ID: 36538018
Correction in my previous post, the formula in cell G2 should be:
=IF((H2&I2)=(D2&E2),"X","")

also, if you wanted to follow slycoder's logic to convert to upper case and test:
=IF(UPPER(H2&I2)=UPPER(D2&E2),"X","")
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36538027
After thinking about it more -

Added a column J and used If condition with Match in column G

Please see attached

CompareColumns-Update.xls
0
 

Author Comment

by:schumarg
ID: 36538028
Yes, the combination in D&E exists in H&I and then place an X in column G.  I'm basicly determining Last Name and First name exist in both sets of columns.  And if they do then place an X in column G.
The values in H&I by default are uppercase, does this matter?
And I should have added that is solution needs to be a macro.
0
 

Author Comment

by:schumarg
ID: 36538044
The names Israel Agosto and Will Altig and the only matches
0
 
LVL 26

Expert Comment

by:pony10us
ID: 36538059
Are you looking for matches? - For example H8 and I8 are the same as D6 and E6 except for case. This is different than comparing columns as that would indicate a one to one relationship in most cases such as C6 = D6.
The comparison slycoder provided would be a one to one comparison and would convert the data to upper case before comparing. This would not work out as true in your sample data since E9 = "Judith" and I9 = "JIM"
0
 

Author Comment

by:schumarg
ID: 36538067
Slycoder

How would this be put into a Macro, that would also move H & I down one row first and then delete column J after the macro finished.
0
 
LVL 5

Accepted Solution

by:
slycoder earned 500 total points
ID: 36538178
Moving down one row wouldn't be required

using your original file - paste this in a module:


Public Sub FindValues()
    ' Insert formula in column J
    Range("J1").Formula = "=H1&""|""&I1"
   
    ' Copy formula down
    Range("J1").Select
    Selection.Copy
    Range("J2:J13").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
   
    ' Enter Values in Column G
    Range("G2").Select
    ActiveCell.Formula = "=IF(ISERROR(MATCH(UPPER(D2&""|""&E2),$J$1:$J$13,)),"""",""X"")"
    Range("G2").Select
    Selection.Copy
    Range("G2:G13").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
   
    ' Paste Special - Values
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
   
    ' Remove Column J
    Columns("J:J").Select
    Selection.ClearContents
   
    Range("G1").Select
End Sub
   
0
 
LVL 12

Expert Comment

by:viralypatel
ID: 36538216
Solution attached with this post.

Things to note:
1. Added column J as a working column (You may choose to keep it hidden)
2. Values in H and I should match values in column D and E (Either all upper case or all lower case or all camel case) Only then will they match - formula used is case sensitive.

(Make note of the formulas in col G and J (Thats all you need)
 CompareColumns.xls
0
 

Author Closing Comment

by:schumarg
ID: 36538311
Great work, thank you very much!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question