Solved

How to combine text in Excel

Posted on 2014-12-16
5
342 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

830 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