I'm trying to modify VBA code comparing two columns.
I found it at exceltip.com:
Sub PullUniques() Dim rngCell As Range For Each rngCell In Range("A2:A40") If WorksheetFunction.CountIf(Range("B2:B40"), rngCell) = 0 Then Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next For Each rngCell In Range("B2:B40") If WorksheetFunction.CountIf(Range("A2:A40"), rngCell) = 0 Then Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next End Sub Since it handles 40 rows I've tried to edit to something like this:
Sub PullUniques() Dim rngCell As Range For Each rngCell In Range("A2").End(xlDown) If WorksheetFunction.CountIf(Range("B2").End(xlDown), rngCell) = 0 Then Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next For Each rngCell In Range("B2").End(xlDown) If WorksheetFunction.CountIf(Range("A2").End(xlDown), rngCell) = 0 Then Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next End Sub It gave me only one row that isn't matching for column. Probably I used "End(xlDown)" in a wrong way.
I created something like this, but it is slow (the file I will compare won't exceed 100k rows anyway):
Sub PullUniques() Dim rngCell As Range For Each rngCell In Range("A2:A99999") If WorksheetFunction.CountIf(Range("B2:B99999"), rngCell) = 0 Then Range("C" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next For Each rngCell In Range("B2:B99999") If WorksheetFunction.CountIf(Range("A2:A99999"), rngCell) = 0 Then Range("D" & Rows.Count).End(xlUp).Offset(1) = rngCell End If Next End Sub Is there a way to optimize it? Why does End(xlDown) fail?
