Combine Cells and Separate Data with Comma

ronicaroman

New Member
Joined
Dec 2, 2011
Messages
25
I came up with a formula, but that would take longer then doing this by hand. Perhaps someone can help me write a macro?? Please :)

A1: 54684
A2: 58321
A3: 38743
A4: 25786

The result would look as such:

A5: 54684,58321,38743,25786

Keep in mind, in reality there would be hundreds of line items

Thanks in advance for your help!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
In your example you had 4 rows of data and the result was in the 5th row. Are you saying that if you had 200 rows of data you would want them all combined in the cell in row 201?
 
Upvote 0
I came up with a formula, but that would take longer then doing this by hand. Perhaps someone can help me write a macro?? Please :)

A1: 54684
A2: 58321
A3: 38743
A4: 25786

The result would look as such:

A5: 54684,58321,38743,25786

Keep in mind, in reality there would be hundreds of line items
I think maybe a UDF (user defined function) might be better for you (I can make it a macro if you really want that)...

Code:
Function Combined(Rng As Range) As String
  Combined = Join(Application.Transpose(Rng), ",")
End Function


HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use Combined just like it was a built-in Excel function. For example,

=Combined(A1:A4)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0

Forum statistics

Threads
1,216,027
Messages
6,128,374
Members
449,445
Latest member
JJFabEngineering

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