Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,786
- Office Version
- 365
- Platform
- Windows
I have the code below that deletes duplicate rows depending on what column I select. At the moment when it deletes a row it takes whatever is in column X from the deleted rows and adds it into the remaning rows column X. I need the values from S and V incorparated too. Thanks,
Code:
Sub delrows()
Dim d As Object, u(), nr&, xcol As Range
Dim c As Range, col, i&, k&, x
Set d = CreateObject("scripting.dictionary")
nr = Cells.Find("*", after:=Cells(1), searchorder:=xlByRows, _
searchdirection:=xlPrevious).Row
ReDim u(1 To nr, 1 To 1)
Set c = Cells(1, Columns.Count)
col = Selection.EntireColumn
Set xcol = Cells.Range("X:X")
For i = 1 To nr
x = col(i, 1)
If Not d.exists(x) Then
d.Add x, i
Else
u(i, 1) = 1
k = k + 1
Cells.Rows(d(x)).Interior.Color = vbCyan
xcol(d(x)) = xcol(d(x)) & " " & xcol(i)
End If
Next i
c.Resize(nr) = u
Cells.Resize(nr, Columns.Count).Sort c, 1
If k > 0 Then Cells.Resize(k, Columns.Count).Delete xlUp
End Sub