View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Compare 2 Lists and Take an Action Q

Hi Sean,

Am Fri, 18 Nov 2016 11:17:48 -0800 (PST) schrieb :

I have 2 Lists of Data on the same sheet

List A is detailed in Columns A-D

List B is detailed in Column G-K

What I want to do is compare certain Columns/Rows in both Lists and for each one that matches, place an X in Column E (covering List A) and a corresponding X in Column L (covering List B). Note the matched values will not be on the same Row in both

So what will be compared? if Col B & D rows matches somewhere with Col H & K an X is placed on the appropriate Row in Cols E & L


try:

Sub CompareList()
Dim LRowA As Long, LRowB As Long, i As Long, j As Long
Dim varA As Variant, varB As Variant

With ActiveSheet
LRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
LRowB = .Cells(.Rows.Count, "G").End(xlUp).Row
varA = .Range("A1:D" & LRowA)
varB = .Range("G1:K" & LRowB)

For i = LBound(varA) To UBound(varA)
For j = LBound(varB) To UBound(varB)
If varA(i, 2) & varA(i, 4) = varB(j, 2) & varB(j, 5) Then
.Cells(i, "E") = "x"
.Cells(i, "L") = "x"
'If there is only one match possible delete the
apostroph in front of next line
'Exit For
End If
Next
Next
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016