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 the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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