Solved

How to combine text in Excel

Posted on 2014-12-16
5
284 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:Iammontoya
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

929 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now