Joining content of a row of cells into one cell

Zembu

New Member
Joined
Apr 9, 2016
Messages
23
Hello All,:eek:

I have searched in your site for a solution for my problem, and have tried various solutions for similar questions, modifying some, but without success. I am running Excel 2003.

I have a row of cells, the whole width of the Excel display, each cell containing a formula that results in display of either a letter or nothing. Here for instance is a formula from one of these cells "=IF(V2="","",HLOOKUP(V20,$J$77:$AI$103,V2,TRUE))" The row commences with the letters, then eventually no letters, as the source for these - from elsewhere in the file runs out.

I want to have all the letters from the cells that display them concatenated into one cell. But there could be any number of letters - usually more than 30 - and the number of letters is not always the same.

Here for instance is a row of cells with letters;

CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER

<tbody>
</tbody>

and below is an output that I can get from a Visual Basic Macro that I copied from elsewhere in this site;

C, , , , , , , , , , CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER, , , , , , , CHCUCXVDLCQOETXMICMNWJAHALISUJODYTRKVCHFPQHYOZMBGWYIYKJKMGVUHTPDHATEHQTVAOTZJJIPSMNBIYWJUMLKLAVHEZQNMWFLACGEHCFNEKYKVYDXLZTXUVYIHBPHCCNUZVKHDUMSFPKDTKKHVR, , , , CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER,

<tbody>
</tbody>

There is more but I think that will do as an example.

Here is the Macro that I used and modified slightly - (thanks to hiker95);

Sub Join_UPCS()
' hiker95, 02/23/2016, ME923576
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
Range("n28").Value = Join(Application.Transpose(Range("n23:n" & lr)), ", ")
Application.ScreenUpdating = True
End Sub

You can see that the above first copies the first letter, then adds commas, then the complete text, then more commas and the rest is from the formulae that exist in the other cells, although on my screen nothing is displayed in these cells.

I tried removing the comma and space at .....Transpose(Range("n23:n" & lr)), ", ") - Thus - ...lr)), "")

This results in a string of letters, still containing an unwanted duplicate of the first, followed by all the other unwanted letters as before.

If anyone can succeed in getting a solution, a further refinement would be to add a space after every 5th letter;

e.g CHCUC JXSYD BJLFL ZVKIY GHFGK KOTKM UDUCX PFZPG ER

Many thanks to any of you who will attempt this. :)
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
CCHCHCCHCUCHCUCCHCUCJCHCUCJXCHCUCJXSCHCUCJXSYCHCUCJXSYDCHCUCJXSYDBCHCUCJXSYDBJCHCUCJXSYDBJLCHCUCJXSYDBJLFCHCUCJXSYDBJLFLCHCUCJXSYDBJLFLZCHCUCJXSYDBJLFLZVCHCUCJXSYDBJLFLZVKCHCUCJXSYDBJLFLZVKICHCUCJXSYDBJLFLZVKIYCHCUCJXSYDBJLFLZVKIYGCHCUCJXSYDBJLFLZVKIYGHCHCUCJXSYDBJLFLZVKIYGHFCHCUCJXSYDBJLFLZVKIYGHFGCHCUCJXSYDBJLFLZVKIYGHFGKCHCUCJXSYDBJLFLZVKIYGHFGKKCHCUCJXSYDBJLFLZVKIYGHFGKKOCHCUCJXSYDBJLFLZVKIYGHFGKKOTCHCUCJXSYDBJLFLZVKIYGHFGKKOTKCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGECHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
just check that cell in row 1 is not blank and concatenate it to previous cell in row 2
formula in B2
=IF(B1="","",A2&B1)

<colgroup><col><col span="2"><col><col><col><col span="37"></colgroup><tbody>
</tbody>
 
Upvote 0
CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
CCHCHCCHCUCHCUCCHCUCJCHCUCJXCHCUCJXSCHCUCJXSYCHCUCJXSYDCHCUCJXSYDBCHCUCJXSYDBJCHCUCJXSYDBJLCHCUCJXSYDBJLFCHCUCJXSYDBJLFLCHCUCJXSYDBJLFLZCHCUCJXSYDBJLFLZVCHCUCJXSYDBJLFLZVKCHCUCJXSYDBJLFLZVKICHCUCJXSYDBJLFLZVKIYCHCUCJXSYDBJLFLZVKIYGCHCUCJXSYDBJLFLZVKIYGHCHCUCJXSYDBJLFLZVKIYGHFCHCUCJXSYDBJLFLZVKIYGHFGCHCUCJXSYDBJLFLZVKIYGHFGKCHCUCJXSYDBJLFLZVKIYGHFGKKCHCUCJXSYDBJLFLZVKIYGHFGKKOCHCUCJXSYDBJLFLZVKIYGHFGKKOTCHCUCJXSYDBJLFLZVKIYGHFGKKOTKCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGCHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGECHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
CHCUCJXSYDBJLFLZVKIYGHFGKKOTKMUDUCXPFZPGER
just check that cell in row 1 is not blank and concatenate it to previous cell in row 2
CHCUC
more info below scroll down6JXSYDformula giving JXSYD
and to the right11BJLFL=MID($D$10,Z18,5)
formula in B216ZVKIY
21GHFGK
=IF(B1="","",A2&B1)26KOTKM
31UDUCX
36PFZPG
41ER
46
51
56
split the big block into 5 letter pieces
then concatenate them adding a space before each one
JXSYD BJLFL ZVKIY GHFGK KOTKM UDUCX PFZPG ER

<tbody>
</tbody>
 
Last edited:
Upvote 0
But there could be any number of letters - usually more than 30...
I am not sure what you meant by "the whole width of the Excel display"... can you tell us an absolute maximum number of letters that there can be (do not count the blanks that may appear between letters, I need to know just a count letters only)?
 
Upvote 0
I am not sure what you meant by "the whole width of the Excel display"... can you tell us an absolute maximum number of letters that there can be (do not count the blanks that may appear between letters, I need to know just a count letters only)?
Ignore the question above, the following macro will output the text you want (with a space after every fifth character) for up to 205 total letters (that number does not count intervening blank cells if any). The macro assumes your letters are in Row 1 and it outputs the text you want to cell A2.
Code:
[table="width: 500"]
[tr]
	[td]Sub SpaceAfterEveryFiveCharacters()
  Range("A2") = RTrim(Format(Application.Trim(Join(Application.Index(Rows(1).Value, 1, 0), "")), "!" & Application.Rept("@@@@@ ", 40)))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hello OldBrewer,

Many Thanks - simple when you know how - I am obviously out of practice! I would like to make it more automatic or more elegant though. i.e. with your present method we have to go to the last cell and copy that. What I mean by that is that the string of cells that have content is of variable length, so I can't for instance have another "Output" cell that would have in it e.g =N2, as N2 might not be the last cell of wanted output.

As I was writing the above, the answer came to me and I have tried it and it works - using your formula from the right hand end of the row copying to the left, we end up with the full text in the leftmost cell

In my file the formula is =IF(IU49="","",IU49&IV51) at the right end and changes to =IF(N49="","",N49&O51) at the left end (in cell N53).

So then it is simple to have an output cell =N53.

So Excellent - Many Thanks again - now how to add a space after every fifth letter?
 
Upvote 0
Many Thanks Rick,

You will have seen that I responded to OldBrewer - (and I see now that he has posted again - I will get back to him too). However, I have now tried your method and it is obviously excellent as well. I may use Old Brewers as it does not involve the use of a Macro hence making it simpler for all users. But for yours tell me - my row of useful text starts at Column N, so how do I modify your program?
 
Upvote 0
Hi Old Brewer,

I have now seen your second part about splitting into 5 and can see that it will work. But Ricks method is easier for that. In my file I have two places where there is that output - in one place I need a space after each 5 and in the other I do not. So I will use your method in the place where I need no spacing and I will use Ricks method in the other. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

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