user3276738
user3276738

Reputation: 1

Excel macro that combines cells and deletes duplicates

I'm trying to locate a macro that would do the following:

1) Go through Column C to locate identical values.

2) If there are identical values in column C and the values in column A are different, put both of those values into column A.

The coding below appears to be close to what I'd like. Such as, deleting the duplicate rows and combining the cells. However, it is not combining the correct cells.

So for example, on rows 65 & 66 I'd like for there to be only 1 row for "CLAIM_NO" 525533564 with "2325 / 2337" in cell A

Sub test()
Dim i As Long
For i = Cells(Rows.Count, "C").End(xlUp).Row To 2 Step -1
  If Cells(i, "C") = Cells(i - 1, "C") Then
    Cells(i - 1, "A") = Cells(i - 1, "A") & " / " & Cells(i - 1, "A")
    Rows(i).Delete
  End If

Upvotes: 0

Views: 1340

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

One tiny problem in the original code:

Sub test()
    Dim i As Long
    For i = Cells(Rows.Count, "C").End(xlUp).Row To 2 Step -1
        If Cells(i, "C") = Cells(i - 1, "C") Then
            Cells(i - 1, "A") = Cells(i - 1, "A") & " / " & Cells(i, "A")
            Rows(i).Delete
        End If
    Next i
End Sub

Upvotes: 1

Related Questions