VBA - combining rows

mrleeson660

New Member
Joined
Aug 16, 2019
Messages
2
Hi guys

Probably quite a simple fix for someone who knows VB.

I found a really useful macro (thank you hiker95) on this site for combining multiple rows with a unique identifier. It's configured to combine the first 2 columns of each row after the unique ID in column 1.

All I need it to do is combine the first 3 columns after the unique ID instead of just 2. I just wondered if someone could help amend the script for me to achieve this?

Any help would be massively appreciated :)



Code is:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Option Explicit
Sub ReorgDataV2()
' hiker95, 02/16/2014, ME758017
Dim r As Long, lr As Long, n As Long, rr As Long, nc As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
For r = 1 To lr
n = Application.CountIf(Columns(1), Cells(r, 1).Value)
If n > 1 Then
For rr = r + 1 To r + n - 1
nc = Cells(r, Columns.Count).End(xlToLeft).Column + 1
Cells(r, nc).Resize(, 2).Value = Cells(rr, 2).Resize(, 2).Value
Cells(rr, 1).Resize(, 3).ClearContents
Next rr
End If
r = r + n - 1
Next r
On Error Resume Next
Range("A1:A" & lr).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
Columns.AutoFit
Application.ScreenUpdating = True
End Sub
[/FONT]
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi & welcome to MrExcel.
Try changing this line
Code:
[FONT=Verdana]Cells(r, nc).Resize(, 2).Value = Cells(rr, 2).Resize(, 2).Value[/FONT]
to
Code:
[FONT=Verdana]Cells(r, nc).Resize(,[COLOR=#ff0000] 3[/COLOR]).Value = Cells(rr, 2).Resize(, [COLOR=#ff0000]3[/COLOR]).Value[/FONT]
 
Upvote 0
Hi & welcome to MrExcel.
Try changing this line
Code:
[FONT=Verdana]Cells(r, nc).Resize(, 2).Value = Cells(rr, 2).Resize(, 2).Value[/FONT]
to
Code:
[FONT=Verdana]Cells(r, nc).Resize(,[COLOR=#ff0000] 3[/COLOR]).Value = Cells(rr, 2).Resize(, [COLOR=#ff0000]3[/COLOR]).Value[/FONT]


Thanks so much that worked perfectly.

Massively appreciate your help.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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