Combine Selected Rows Data Horizontally But Not Vertically

miketurn

Active Member
Joined
Dec 8, 2016
Messages
268
Hello Everyone,

I believe this will probably be one of the last I ask for in a while, hopefully :)
I am looking for a macro that will allow you to combine data horizontally (by columns) but NOT vertically (by rows) of single or multiple SELECTED cells in Column A.

1.) I would like to be able to do this by simply SELECTING one or more cells in Column A and the macro will know to look to the RIGHT of the selection in COLUMN A and will take any data found in that selected Column A row and will add it to the end of the data found in Column A.

2.) I would like this macro to retain the cells background fill color in Column A, meaning don't remove the fill color.

3.) I would like this macro to add a SINGLE SPACE between each piece of combined text added to the Column A row.
(See Example #1 Below)

Note:
The specific row numbers shown in the following example, are just an example, I would like this to be able to be applied to any SELECTED Column A Rows.

EXAMPLE #1
BEFORE
|____A____|____B____|____C____|
1 apple____orange____banana
2 apple____orange____banana
3 apple______________banana
4 _________orange____banana
5 apple____orange____banana
6 apple____orange__________

If you SELECT Column A's cells 2,3,4 and 6 and apply the macro you would get

AFTER
|____A____|____B____|____C____|
1 apple____orange____banana
2 apple orange banana
3 apple banana
4 orange banana
5 apple____orange____banana
6 apple orange

Notice rows 1 and 5 remain the same because they were NOT selected.

Notice in row 3 there is only a single space between apple and banana .
Notice in row 4 there is not a space at the beginning.
The handling of these two "space" issues can be achieved by adding the following links macro to this macro.

https://www.mrexcel.com/forum/excel-questions/991831-remove-extra-spaces-within-cells.html

Thank You to anyone who reads this and to anyone who provides a solution.
Any questions, please let me know.
 
Last edited:
@Rick
Thank You for your response. This works, but like you said if an item happens to already have a space in between it will also get replaced with the new separator, so the user has to make sure they are aware that no spaces exist.

@Tetra201
Thank You for your response, I tested out your modification and it works great, I really appreciate it.

Thank You both again for coming back to help me out, I apologize for opening up this thread again.
Hopefully others will find this tool just as valuable.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
@Rick
Thank You for your response. This works, but like you said if an item happens to already have a space in between it will also get replaced with the new separator, so the user has to make sure they are aware that no spaces exist.
The problem was your examples strongly hinted that there were no spaces in your text... in the future when you ask a question, you should strive to give us representative examples of your data and its layout rather than try to simplify things for us.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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