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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,226,116
Messages
6,189,057
Members
453,523
Latest member
Don Quixote

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