Solved

How to combine text in Excel

Posted on 2014-12-16
5
340 Views
Last Modified: 2014-12-17
In the attached screenshot, you see my attempts at combining the text assembled in column "E" - the fifth column over from the left.

What I want to do is craft an "forumula" that combines all of the text in column E so when I combine it with "CREATE TABLE 'volte7' (..." I'll have "CREATE TABLE 'volte7' ('EndDate' DATE NOT NULL, 'Num Days' varchar(20) DEFAULT NULL, 'Area' varchar(150) DEFAULT NULL...

...and so on.

You can see where I started to write out in column G "=E4&""&E5&" and I stopped because I was wondering if there was a quicker way to do it.

Thoughts?

screenshot
0
Comment
Question by:brucegust
5 Comments
 
LVL 19

Expert Comment

by:Montoya
ID: 40503175
short of using CONCATENATE  e.g. =CONCATENATE("CREATE TABLE ",A2&" ",A3&" ",A4)

you could write VBA that iterates through each row and does the same thing. Were you trying to stay away from VBA?
0
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40503176
I would do that by starting with a single value =RC-1 (i.e. the cell to the left)
then for the next row down in the column:
=R-1C &  RC-1
and drag that down.

The bottom row then contains the entire formula.

Sorry to express that in normal notation
start with
=E5 (in cell F5)
=F5 & "," & E6 (in cell F6)
etc
0
 

Author Comment

by:brucegust
ID: 40503200
Simon, that did it!

Thanks!
0
 
LVL 81

Expert Comment

by:byundt
ID: 40503209
Consider using a user-defined function (UDF) to build your string with a worksheet formula like:
=StringBuilder(E4:E28)

To create a UDF:
1. ALT + F11 to open the VBA Editor
2. Insert...Module to create a blank module sheeet
3. Paste the following code there:
Function StringBuilder(rg As Range) As String
Dim s As String
Dim cel As Range
For Each cel In rg.Cells
    If cel.Value <> "" Then s = s & cel.Value
Next
StringBuilder = s
End Function

Open in new window

4. ALT + F11 to return to the worksheet userinterface
5. Use the function wizard (fx icon to left of formula bar) the first time you need to use the new function. It will be found under category "User defined".
StringBuilderQ28582044.xlsm
0
 
LVL 18

Expert Comment

by:Simon
ID: 40503217
Glad to help. If you do EXACTLY the same thing a lot, it would be worth having a UDF for it, but for one-off quickies, I find formulae like the ones I posted the fastest way to achieve the desired result.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question