Cannot delete duplicate row

Rangolijaro

New Member
Joined
Jun 10, 2019
Messages
4
Hi,

Please help on the following code supposed to delete rows with duplicate values in P column and keep the first instance after combining the values in the 8th and 10th columns, but I get the 1004 Delete method of Range class failed error on the EntireRow.

Sub MG02Sep59()
Dim Rng As Range, Dn As Range, n As Long, nRng As Range
Set Rng = Range(Range("P2"), Range("P" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
.Add Dn.Value, Dn
Else
If nRng Is Nothing Then Set nRng = _
Dn Else Set nRng = Union(nRng, Dn)
.Item(Dn.Value).Offset(, 8) = .Item(Dn.Value).Offset(, 8) + Dn.Offset(, 8)
.Item(Dn.Value).Offset(, 10) = .Item(Dn.Value).Offset(, 10) + Dn.Offset(, 10)

End If
Next
If Not nRng Is Nothing Then nRng.EntireRow.Delete
End With
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
i tried again and it would work on <10 rows <10 columns worksheet but not on a 300rows 300columns worksheet. is there any limit of #of items on dictionary?
 
Upvote 0
Is the sheet protected?
Do you have any merged cells?
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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