ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compare two lists and producing a third list (https://www.excelbanter.com/excel-programming/381352-re-compare-two-lists-producing-third-list.html)

merjet

Compare two lists and producing a third list
 
Sub NoMatch()
Dim rng1 As Range
Dim rng2 As Range
Dim c1 As Range
Dim c2 As Range
Dim bFound As Boolean
Dim iRow As Integer
Dim iCt As Integer

'change ranges to fit data
Set rng1 = Sheets("Sheet1").Range("a1:a4")
Set rng2 = Sheets("Sheet2").Range("a1:a4")
For iCt = 1 To 2
If iCt = 2 Then
'change ranges to fit data
Set rng2 = Sheets("Sheet1").Range("a1:a4")
Set rng1 = Sheets("Sheet2").Range("a1:a4")
End If
For Each c1 In rng1
bFound = False
For Each c2 In rng2
If c1 = c2 Then
bFound = True
Exit For
End If
Next c2
If bFound = False Then
iRow = iRow + 1
Sheets("Sheet3").Cells(iRow, 1) = c1
End If
Next c1
Next iCt
End Sub



All times are GMT +1. The time now is 06:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com