i am new to VBA, i got a task to compare two columns.macro should compares the entries on each column in the active worksheet with respect to the other column and highlights the differences. It also adds the different values to another sheet for both columns. i have created the code with the help of google & youtube and its working fine. but the issue is if we feed input around 30000+ rows, macro took more time to complete the task. Is there any way to reduce the timing. i have pasted the code below. please check and suggest.
'Looping into the columns'
For r = 2 To LastRow
Row2inCol1 = Cells(r, Column1.Column).Value
Row2inCol2 = Cells(r, Column2.Column).Value
'Searching 1st row of column1 with column2
If Row2inCol1 <> "" Then
Set inCol2 = Column2.Find(Row2inCol1)
If inCol2 Is Nothing Then
Cells(r, Column1.Column).Interior.ColorIndex = 31
'Adding highlighted results in different sheet
Col1Diff = Col1Diff + 1
Sheets("Results").Cells(Col1Diff + 1, 1).Value = Row2inCol1
End If
End If
'Searching "2nd row of column2 with column1
If Row2inCol2 <> "" Then
Set inCol1 = Column1.Find(Row2inCol2)
If inCol1 Is Nothing Then
Cells(r, Column2.Column).Interior.ColorIndex = 31
'Adding highlighted results in different sheet
Col2Diff = Col2Diff + 1
Sheets("Results").Cells(Col2Diff + 1, 2).Value = Row2inCol2
End If
End If
Next r
Microsoft documentation: