Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Cell with multiple lines of text into one line of text

Tags:

excel

vba

I have about 4000 cells, each with about 4 separate lines of text. Each line of texts has been entered using the ALT+ENTER method.

Can anybody suggest a way, either VBA or Excel command/method to convert each of of these cells into one line, with spaces between the words.

Example: Current Cell 1:

  • About
  • Horse
  • Dog

Need: Cell 1:

  • About Horse Dog

Any help is much appreciated

like image 974
Clauric Avatar asked Jul 31 '15 15:07

Clauric


People also ask

How do I combine text lines in Excel?

Type = and select the first cell you want to combine. Type & and use quotation marks with a space enclosed. Select the next cell you want to combine and press enter. An example formula might be =A2&" "&B2.

How do you fix long text in a single cell with multiple lines?

On the Home tab, in the Alignment group, click Wrap Text. (On Excel for desktop, you can also select the cell, and then press Alt + H + W.) Notes: Data in the cell wraps to fit the column width, so if you change the column width, data wrapping adjusts automatically.


2 Answers

To do this without VBA:

Use find and replace.

In the find what box, hold ALT and type 0010 (ASCII code for line feed is 10 - you will not see anything, but it's a new line character).

In the replace box, simply type a space character or any delimiter.

Click on Replace all buttton.

like image 124
KFichter Avatar answered Nov 15 '22 08:11

KFichter


Try this short macro:

Sub dural()
    Dim rng As Range
    Set rng = Selection
    rng.Replace what:=Chr(10), lookat:=xlPart, replacement:=" "
End Sub
like image 21
Gary's Student Avatar answered Nov 15 '22 09:11

Gary's Student