VBA Combine Rows

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi I am trying to combine Rows based on duplicate values but need to comma delimit one columns of cells at the same time, Currently I am using the code below however it takes a long time when there is a lot of data, can someone help make this process faster please

VBA Code:
Sub CombineRows()
'
Dim j As Long, c As Range

    Application.ScreenUpdating = False
    j = 1
    Do While j < ActiveSheet.UsedRange.Rows.Count
        Set c = Cells(j, 4)
        If Not c.Value = "" Then
            If c.Value = c.Offset(1).Value Then
                With c
                    .Offset(, 2).Value = .Offset(, 2).Value & "," & .Offset(1, 2).Value
                    .Offset(1).EntireRow.Delete
                End With
            Else
                j = j + 1
            End If
        End If
    Loop
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about
VBA Code:
Sub decadence()
   Dim i As Long
   Dim Rng As Range
   
   For i = Range("D" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, 4) = Cells(i - 1, 4) And Cells(i, 4) <> "" Then
         Cells(i - 1, 6) = Cells(i - 1, 6) & "," & Cells(i, 6).Value
         If Rng Is Nothing Then Set Rng = Rows(i) Else Set Rng = Union(Rng, Rows(i))
      End If
   Next i
   If Not Rng Is Nothing Then Rng.Delete
End Sub
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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