Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract First line in multiline cell in Excel

Status
Not open for further replies.

Carrion

Technical User
Jul 26, 2002
27
US
Here is the dilemma I have an Excel table with cells that contain multiple lines. Here is an example:


-----------------------
Setup:
Theater for 160
tables in back
-----------------------


I need to be able store the first line in the cell as a variable (in this case "Setup:").

The text varies from cell to cell, so I need some code to extract the fist line only.

Thanks
 
Hi,

If you are using Excel 2k or better
Code:
FirstLine = Split(Selection.value, vbLf)(0)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
You can do the same job as the VBA with a simple worksheet formula:
=LEFT(A1,FIND(CHAR(10),A1,1))

The VBA equivalent of this (works in Excel 97) is:
Code:
Dim cel as Range
Set cel=Range("A1")   'Source of the multi-line text
cel.offset(0,1)=Left(cel,InStr(1,A1,Chr(10)))    'Put first line in adjacent cell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top