excel – VBA code to compare two columns


I have two different columns in a worksheet, and I want to compare the values ​​of both and want to display in the third column, if the values ​​are present in both columns or if they are present in a column and absent in another, and vice versa. vice versa. Please respond as soon as possible, it is urgent.

Dim ListA As Range
Dim ListB As Range
Dim c As Range
Call without protection

ListARange = Cells (Rows.Count, "A"). End (xlUp) .Row find the last line with the data in column A
ListBRange = Cells (Rows.Count, "B"). End (xlUp) .Row find the last line with the data in column B

Set ListA = Range ("A2: A" & ListARange) Set your range only up to the last line with data
Set ListB = Range ("B2: B" & ListBRange)
Application.ScreenUpdating = False

Range ("C1"). Value = "Files in A that are not in B"
Range ("D1"). Value = "Files in B that are not in A"
Beach ("E1"). Value = "Matching Files"

For each c in ListA
If Application.CountIf (ListB, c) = 0 then
Cells (Cells (Rows.Count, "C"). End (xlUp) .Row + 1, "C"). Value = c
ElseIf Application.CountIf (ListB, c)> = 1 Next
Cells (Cells (Rows.Count, "E"). End (xlUp) .Row + 1, "E"). Value = c
End if
Next c

For each c in the listB
If Application.CountIf (ListA, c) = 0 Then Cells (Cells (Rows.Count, "D"). End (xlUp) .Row + 1, "D"). Value = c
Next c

Application.ScreenUpdating = True

Protection of the call