Compare 3 column values wit other 3 column values?

jamiguel77

Active Member
Joined
Feb 14, 2006
Messages
378
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
  2. Web
hi all
i have this:

4 AA 100.67 1 FF 310.21
2 BB 210.56 3 GG 119.12
1 FF 310.21 2 BB 210.56
3 HH 119.12 4 AA 100.67


if you see, all 3 first columns exist on the other group... right

Except

3 HH 119.12

and

3 GG 119.12


how to detect this?


thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Re: how to compare 3 column values wit other 3 column values?

Here is one way. It assumes data in columns A:F and uses columns H:I as helper colulmn, then removes contents of H:I when mismatched Items are identified.
Code:
Sub t()
For Each c In Range("A2", Cells(Rows.Count, 1).End(xlUp))
    c.Offset(, 7) = c.Value & c.Offset(, 1).Value & c.Offset(, 2).Value
Next
For Each c In Range("D2", Cells(Rows.Count, 4).End(xlUp))
    c.Offset(, 5) = c.Value & c.Offset(, 1).Value & c.Offset(, 2).Value
Next
For Each c In Range("H2", Cells(Rows.Count, 8).End(xlUp))
    If Application.CountIf(Range("I:I"), c.Value) = 0 Then
        c.Offset(, -7).Resize(, 3).Interior.Color = vbYellow
    End If
Next
For Each c In Range("I2", Cells(Rows.Count, 9).End(xlUp))
    If Application.CountIf(Range("H:H"), c.Value) = 0 Then
        c.Offset(, -5).Resize(, 3).Interior.Color = vbYellow
    End If
Next
Range("H:I").EntireColumn.ClearContents
End Sub
 
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

The code I posted will highlight only the three cell range that does NOT match values in the other set of columns. In the tests that I ran the code works as expected. I cannot tell from the images posted if it worked because the beginning cells were already highlighted. The OP did not specify what to do if matches were found or not found, so I improvised and opted to show only non-matching cells. What do you want to see as a result of the comparison between the two sets of columns?
 
Last edited:
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

hi all
i have this:

4 AA 100.67 1 FF 310.21
2 BB 210.56 3 GG 119.12
1 FF 310.21 2 BB 210.56
3 HH 119.12 4 AA 100.67

if you see, all 3 first columns exist on the other group... right
Except

3 HH 119.12

and

3 GG 119.12

how to detect this?

thanks

Maybe the formulas below can help:

In D2 and copy down

=IF(SUM(--(MMULT(COUNTIF(A2:C2,$E$2:$G$5),{1;1;1})=3)),"","Not ")&"Found"

In H2 and copy down

=IF(SUM(--(MMULT(COUNTIF(E2:G2,$A$2:$C$5),{1;1;1})=3)),"","Not ")&"Found"


ABCDEFGH
11231-34564-6
24AA100,67Found1FF310,21Found
32BB210,56Found3GG119,12Not Found
41FF310,21Found2BB210,56Found
53HH119,12Not Found4AA100,67Found
6
******************************************************

<tbody>
</tbody>


Markmzz
 
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

It is possible that you have leading or trailing spaces that caused the results you gor from the code. This version will eliminate that problem.

Code:
Sub t2()
For Each c In Range("A2", Cells(Rows.Count, 1).End(xlUp))
    c.Offset(, 7) = Trim(c.Value) & Trim(c.Offset(, 1).Value) & Trim(c.Offset(, 2).Value)
Next
For Each c In Range("D2", Cells(Rows.Count, 4).End(xlUp))
    c.Offset(, 5) = Trim(c.Value) & Trim(c.Offset(, 1).Value) & Trim(c.Offset(, 2).Value)
Next
For Each c In Range("H2", Cells(Rows.Count, 8).End(xlUp))
    If Application.CountIf(Range("I:I"), c.Value) = 0 Then
        c.Offset(, -7).Resize(, 3).Interior.Color = vbYellow
    End If
Next
For Each c In Range("I2", Cells(Rows.Count, 9).End(xlUp))
    If Application.CountIf(Range("H:H"), c.Value) = 0 Then
        c.Offset(, -5).Resize(, 3).Interior.Color = vbYellow
    End If
Next
Range("H:I").EntireColumn.ClearContents
End Sub
 
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

JLGWhiz thanks Worked the code.....
is possible explain the code? (if not not problem, i try understand).. thanks

markmzz Worked too...... is possible explain pls :)

i am grateful with the help really impresionant both...

Thanks, much thanks
 
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

JLGWhiz thanks Worked the code.....
is possible explain the code?

Loops through to concatenate the values in columns A:C and then columns D:F and place the concatenated range values in columns H:I where it can then compare them as single values rather than three separate values. Once the concatenation is complete then it loops through column H to check column I for a match, If none is found it then highlights the corrseponding range of cells in A:C. Tha same is done with column I against column H and unmatched items are then highlighted in columns D:F. Once all items are checked, the helper columns H:I are cleared of data.
 
Last edited:
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

markmzz Worked too...... is possible explain pls :)

You're welcome and thanks for the feedback.

I think that the best way to understand the formula is to browse to the formula (step by step).

Lets go:

ABCDEFGHIJK
11231-34564-6Formula in D5Details
24AA100,67Found1FF310,21FoundSteps=IF(SUM(--(MMULT(COUNTIF(A5:C5,$E$2:$G$5),{1;1;1})=3)),"","Not ")&"Found"Start formula
32BB210,56Found3GG119,12Not Found1=IF(SUM(--(MMULT({0\0\0;1\0\1;0\0\0;0\0\0},{1;1;1})=3)),"","Not ")&"Found"Counts the number of occurrences of the caracters 3, HH
41FF310,21Found2BB210,56Foundand 119,12 in the "columns" E, F e G and create a matrix
53HH119,12Not Found4AA100,67Found4 rows x 3 columns with the count of the found caracters
6{0\0\0;1\0\1;0\0\0;0\0\0}.
72=IF(SUM(--({0;2;0;0}=3)),"","Not ")&"Found"Now, the function MMULT multiplies the matrix 4x3
8{0\0\0;1\0\1;0\0\0;0\0\0} for the matrix 3x1 {1;1;1} to create
9a matrix 4x1 {0;2;0;0} with the sum (row to row) of the founds
10caracters with the function COUNTIF.
113=IF(SUM(--({FALSE;FALSE;FALSE;FALSE})),"","Not ")&"Found"After that, compare the values of the matrix 4x1 with the
12number 3 to know if the 3 caracters was found or not in
13one row {FALSE;FALSE;FALSE;FALSE}.
144=IF(SUM({0;0;0;0}),"","Not ")&"Found"Now, the --(the same of -1*-1*) change FALSE to zero
15({0;0;0;0}).
165=IF(0,"","Not ")&"Found"Then, the function SUM sum the values of the matrix 4x1
17({0;0;0;0}) and the result is zero (0).
186="Not "&"Found"After that, as zero is like FALSE, then the IF function choose the
19option "Not "(third argument of the function IF).
207="Not found"Finally, we have the junction of the two texts and the result is
21"Not found"
22
****************************************************************************************************************************************************************************************************

<tbody>
</tbody>

I hope that the step by step above help you to understand the formula.

Markmzz
 
Upvote 0
Re: how to compare 3 column values wit other 3 column values?

Thanks, Understand now.

Really much thanks.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top