How do I Merge Dynamic numbers of Cells

hellothere4

New Member
Joined
May 9, 2011
Messages
17
Hello, I can have 3 examples of matrixes of cells, and the initial input and output:

input
(1)
a1 b1 c1 d1
a2 b2 c2 d2
(2)
a1 b1 c1 d1 e1
a2 b2 c
(3)
a1 b1 c1 d1 e1
a2 b2 c2 d2 e2
a3 b3 c3 d3 e3
a4 b4 c4 d4 e4
a5

output
(1)
(a1,b1,c1,d1)
(a2,b2,c2,d2)
(2)
(a1,b1,c1,d1,e1)
(a2,b2)
(3)
(a1,b1,c1,d1,e1)
(a2,b2,c2,d2,e2)
(a3,b3,c3,d3,e3)
(a4,b4,c4,d4,e4)
(a5)

and I want to be able to merge/replace the rows so that the first cell looks like this (a1,b1,c1,d1,e1). Now, I could do A1 ="("&a1&","&....","&e1&")" however I need the merge to work without needing to know the number of columns, which could be 1,4,20. And then, I need it to move down and repeat the step until it reaches a cell in column 1 which has no data. So, there are really two places I need help, merging with a dynamic number of columns, and then repeating this through a dynamic number of rows. Thanks for the help
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Update: OK, I found this about merging cells which completes a huge chunk from http://excel.tips.net/T002417_Combining_Multiple_Rows_in_a_Column.html. but it's not counting number of columns per row, and not traversing rows.


Sub Combine() Dim J As Integer If Selection.Cells.Count > 1 Then For J = 2 To Selection.Cells.Count Selection.Cells(1).Value = _ Selection.Cells(1).Value & " " & _ Selection.Cells(J).Value Selection.Cells(J).Clear Next J End If End Sub</pre>
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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