Macro to Remove duplicates and display a message with the particular row number is deleted

Siri Jasthi

New Member
Joined
Apr 24, 2018
Messages
9
Hi ,
I have four rows as mentioned below .

Column1 Column2 Column3 Column4 Column5
Apple Bat Cat Dog Egg
Ant Bag Can Den Eat
Apple Bat Cat Dog Egg
Air Big Car Dun Eagle

In the above i m having Row 3 same as Row 1 then macro should delete Row 3 and display a message that Row 3 is deleted.Please help me to write macro .
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi ,
I have four rows as mentioned below .

Column1 Column2 Column3 Column4 Column5
Apple Bat Cat Dog Egg
Ant Bag Can Den Eat
Apple Bat Cat Dog Egg
Air Big Car Dun Eagle

In the above i m having Row 3 same as Row 1 then macro should delete Row 3 and display a message that Row 3 is deleted.Please help me to write macro .

Code:
Private Sub testY()


Dim dict As Object
Dim rowCount As Long
Dim strVal As String


Set dict = CreateObject("Scripting.Dictionary")


rowCount = Sheet1.Range("A1").CurrentRegion.Rows.Count


Do While rowCount > 1


With Sheet1
  strVal = .Cells(rowCount, 1).Value2 & .Cells(rowCount, 2).Value2 & .Cells(rowCount, 3).Value2 & .Cells(rowCount, 4).Value2 & .Cells(rowCount, 5).Value2


  If dict.exists(strVal) Then
    .Rows(rowCount).Interior.ColorIndex = 3
        MsgBox "You are about to delete Row " & rowCount, vbOKOnly
            .Rows(rowCount).EntireRow.Delete
                .Rows(rowCount - 1).Interior.ColorIndex = Null
  Else
    dict.Add strVal, 0
  End If
  rowCount = rowCount - 1
End With
Loop


Set dict = Nothing


Application.ScreenUpdating = True


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top