close

Does anybody know of a formula that can look at a sentence of say 3 or 4
words and then look for the spaces inbetween the words and put each word
in a different cell underneath each other?--
sparx
------------------------------------------------------------------------
sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
View this thread: www.excelforum.com/showthread...hreadid=515292You can just about do it with worksheet functions, but it's rather
long-winded (and dependent on correct input)

With the sentence in A1
A2: =LEFT(A1,FIND(quot; quot;,A1)-1)
A3: =MID(A1,FIND(quot; quot;,A1) 1,FIND(quot; quot;,A1,FIND(quot; quot;,A1) 1)-FIND(quot; quot;,A1)-1)
A4: quot;and so onquot;...

It's a bit easier if you have some helper cells that just contain the
positions of the spaces:

A2: =FIND(quot; quot;,$A$1)
A3: =FIND(quot; quot;,$A$1amp;quot; quot;,A2 1) ' append space to avoid special case for
last word
and copy the A3 down a few rows
B2: =LEFT($A$1,A2-1)
B3 =MID($A$1,A2 1,A3-A2-1)
and copy B3 down.

HTH
Andrewsparx wrote:
gt; Does anybody know of a formula that can look at a sentence of say 3 or 4
gt; words and then look for the spaces inbetween the words and put each word
gt; in a different cell underneath each other?
gt;
gt;
gt; --
gt; sparx
gt; ------------------------------------------------------------------------
gt; sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
gt; View this thread: www.excelforum.com/showthread...hreadid=515292VBA has a function named SPLIT which does what you want. The syntax for the
function is SPLIT(String value, Delimiter)

If you place a sentence in column A row 1 of Sheet 1, and place another in
column a row 2, you can run the following code to parse the words separated
by spaces and place them on sheet 2 column A in a column. Hope it helps to
point you in the general direction.

Sub SplitSentences()

Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim l As Long
Dim strSentence As String
Dim varArray As Variant
Dim varItems As Variant

Set wb = ActiveWorkbook
Set ws1 = wb.Sheets(quot;Sheet1quot;)
Set ws2 = wb.Sheets(quot;Sheet2quot;)

ws1.Activate
Range(quot;A1quot;).Select
strSentence = ActiveCell.Value

Do Until strSentence = quot;quot;
ws2.Activate
Range(quot;A1quot;).Select
varArray = Split(strSentence, quot; quot;)
varItems = varArray
For Each varItems In varArray
ActiveCell.Offset(l).Value = varItems
l = l 1
Next varItems
ws1.Activate
ActiveCell.Offset(1).Select
strSentence = ActiveCell.Value
Loop

Set wb = Nothing
Set ws1 = Nothing
Set ws2 = Nothing

--
Kevin Backmannquot;sparxquot; wrote:

gt;
gt; Does anybody know of a formula that can look at a sentence of say 3 or 4
gt; words and then look for the spaces inbetween the words and put each word
gt; in a different cell underneath each other?
gt;
gt;
gt; --
gt; sparx
gt; ------------------------------------------------------------------------
gt; sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
gt; View this thread: www.excelforum.com/showthread...hreadid=515292
gt;
gt;

On Wed, 22 Feb 2006 07:38:30 -0600, sparx
gt; wrote:

gt;
gt;Does anybody know of a formula that can look at a sentence of say 3 or 4
gt;words and then look for the spaces inbetween the words and put each word
gt;in a different cell underneath each other?

1. Use the Data/Text to Columns wizard with lt;spacegt; as the delimiter.

or

2. Download and install Longre's free morefunc.xll add-in from
xcell05.free.fr

Then, with your sentence in A1:

B1:=REGEX.MID($A1,quot;\w quot;,COLUMNS($A:A))

and copy/drag across as far as needed.

If it is an issue, there is an option to distribute the morefunc.xll add-in
with the workbook.--ron

You will first need to transpose the data to be in one column only.

Select the column you want to split
In the quot;Dataquot; menu, select quot;Text to Columnsquot;
Select quot;Delimitedquot; and then click quot;Nextquot;
Check only the box next to Space, and maybe the one next to quot;Treat
consecutive delimiters as onequot; and then click quot;Finishquot;

This will split all cells in the column you selected and push the words to
the right in other cells as you described you need. You can then tranpose
the data to get the orientation you want.
quot;sparxquot; wrote:

gt;
gt; Does anybody know of a formula that can look at a sentence of say 3 or 4
gt; words and then look for the spaces inbetween the words and put each word
gt; in a different cell underneath each other?
gt;
gt;
gt; --
gt; sparx
gt; ------------------------------------------------------------------------
gt; sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
gt; View this thread: www.excelforum.com/showthread...hreadid=515292
gt;
gt;


Thanks for the response - I will try each and will try it in my
worksheet.

Thanks again.--
sparx
------------------------------------------------------------------------
sparx's Profile: www.excelforum.com/member.php...oamp;userid=16787
View this thread: www.excelforum.com/showthread...hreadid=515292

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()