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