Macro to Merge Rows Based on Condition

Nani520

New Member
Joined
Sep 22, 2021
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

Appreciate if anyone can assist to build a macro to merge 2 or multiple rows if conditions met (Merged into 1 row based on No).
Any help is most appreciated! Thanks in advance.

Initial Data:
NoAvailStart DateFigureReference
1Lee1/2/2015123456951623
2Low1/6//2016456789852165
2Low1/6//2016987456
3Lim6/8/2017639852785412
3Lim6/8/2017741258652398
3Lim6/8/2017845126
4John9/11/2018958746741852

Result:

NoAvailStart DateFigureReference
1Lee1/2/2015123456951623
2Low1/6//2016456789/987456852165
3Lim6/8/2017639852/741258785412/652398/845126
4John9/11/2018958746741852
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this:
VBA Code:
Sub Test()
Dim i As Long, Lr As Long, j As Long, K As Long, M As Long, T As String, F As String
Lr = Range("A" & Rows.Count).End(xlUp).Row
K = 2
Range("G1:K1").Value = Range("A1:E1").Value
For i = 2 To Lr
Range("G" & K).Value = Range("A" & i).Value
Range("H" & K).Value = Range("B" & i).Value
Range("I" & K).Value = Range("C" & i).Value
M = Range("A2:A" & Lr).Find(Range("A" & i).Value, , , , , xlPrevious, , , True).Row
For j = i To M
If Range("D" & j).Value <> "" Then T = T & "/" & Range("D" & j).Value
If Range("E" & j).Value <> "" Then F = F & "/" & Range("E" & j).Value
Next j
Range("J" & K).Value = Right(T, Len(T) - 1)
Range("K" & K).Value = Right(F, Len(F) - 1)
K = K + 1
i = M
T = ""
F = ""
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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