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
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