Solved

How to combine text in Excel

Posted on 2014-12-16
5
218 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:
SimonAdept 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 80

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:SimonAdept
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

762 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

18 Experts available now in Live!

Get 1:1 Help Now