In this article, we will create a macro to check duplication and remove duplicate values from two consecutive columns.
Raw data consists of target details, which includes Agent name, Target model name and Desired model name.
In this article, we want to delete those records, which have similar Target model name and desired model name.
LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row
The above code is used to get the row number of the last cell.
For i = LastRow To 12 Step -1
The above For loop is used for reverse looping. It will start looping from last row till the 12th row.
If Cells(i, 2) = Cells(i, 3) Then
In above code, we have compared values in the cells of 2nd column with 3rd column.
The above code is used to delete the entire row.
Please follow below for the code
Option Explicit Sub DeleteMatches() 'Declaring variables Dim LastRow, i As Long 'Getting the row number of last cell LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row 'Looping from last row to 12th row For i = LastRow To 12 Step -1 If Cells(i, 2) = Cells(i, 3) Then Rows(i).Delete End If Next End Sub
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at email@example.com