Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Split string into seperate cells

Hi,

I have a text string I need to split into seperate cells for each
word.

For example, if this was the value of A4;

The fat cat jumped over the mat

I would want;

B5 The
C5 fat
D5 cat
E5 jumped

etc etc

Each of the words in the string may be different lengths but they will
always be seperated by a space.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Split string into seperate cells

Look at DataText to columns

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"keri" wrote in message oups.com...
| Hi,
|
| I have a text string I need to split into seperate cells for each
| word.
|
| For example, if this was the value of A4;
|
| The fat cat jumped over the mat
|
| I would want;
|
| B5 The
| C5 fat
| D5 cat
| E5 jumped
|
| etc etc
|
| Each of the words in the string may be different lengths but they will
| always be seperated by a space.
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Split string into seperate cells

On Apr 12, 11:14 am, "Niek Otten" wrote:
Look at DataText to columns

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"keri" wrote in ooglegroups.com...

| Hi,
|
| I have a text string I need to split into seperate cells for each
| word.
|
| For example, if this was the value of A4;
|
| The fat cat jumped over the mat
|
| I would want;
|
| B5 The
| C5 fat
| D5 cat
| E5 jumped
|
| etc etc
|
| Each of the words in the string may be different lengths but they will
| always be seperated by a space.
|


Or set up a looping istr search

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Split string into seperate cells

On 12 Apr 2007 12:35:49 -0700, "Craig B" wrote:

Or set up a looping istr search


OR just use the Split function
--ron
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Split string into seperate cells

On 13 Apr, 00:41, Ron Rosenfeld wrote:
On 12 Apr 2007 12:35:49 -0700, "Craig B" wrote:

Or set up a looping istr search


OR just use the Split function
--ron


Hi,

Thanks for your replies. I tried using text to columns but it appears
I have to specify the length of the array, so this does not work.

I had not heard of the split function but have found this code;

Sub SplitDemo()
Dim txt As String
Dim x As Variant
Dim i As Long
txt = ActiveSheet.Range("a23")
x = Split(txt, " ")
For i = 0 To UBound(x)
Debug.Print x(i)
Next i

What I am unsure how to do is split the text into columns B23 - L23 as
I am unsure how to reference each part of the split text to name a
destination.

Many thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Split string into seperate cells

Hi Keri, try this

Sub single_Split()
'
Dim x As String, s As Variant

x = Range("A4")
s = Split(x, " ")
Range("B5").Value = s(0)
Range("C5").Value = s(1)
Range("D5").Value = s(2)
Range("E5").Value = s(3)
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Split string into seperate cells

On 13 Apr 2007 01:30:00 -0700, "keri" wrote:

On 13 Apr, 00:41, Ron Rosenfeld wrote:
On 12 Apr 2007 12:35:49 -0700, "Craig B" wrote:

Or set up a looping istr search


OR just use the Split function
--ron


Hi,

Thanks for your replies. I tried using text to columns but it appears
I have to specify the length of the array, so this does not work.

I had not heard of the split function but have found this code;

Sub SplitDemo()
Dim txt As String
Dim x As Variant
Dim i As Long
txt = ActiveSheet.Range("a23")
x = Split(txt, " ")
For i = 0 To UBound(x)
Debug.Print x(i)
Next i

What I am unsure how to do is split the text into columns B23 - L23 as
I am unsure how to reference each part of the split text to name a
destination.

Many thanks.


Text to columns has an option which allows you to specify a delimiter which, in
your case, you would specify a <space. Of course, since your source is in A4
and your destination is B5, you might also have to do some copy/paste
operations.

To use the Split function, given your parameters in the OP, try this:

-------------------------------------------------

Option Explicit

Sub ParseString()
Dim rSrc As Range
Dim rDest As Range
Const sDelim As String = " "
Dim Temp As Variant
Dim i As Long

Set rSrc = Range("A4")
Set rDest = Range("B5")

Temp = Split(rSrc.Text, sDelim, -1)

For i = 0 To UBound(Temp)
rDest.Offset(0, i).Value = Temp(i)
Next i

End Sub
==================================================



--ron
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Split string into seperate cells

On Fri, 13 Apr 2007 03:19:51 -0700, Les Stout wrote:

Hi Keri, try this

Sub single_Split()
'
Dim x As String, s As Variant

x = Range("A4")
s = Split(x, " ")
Range("B5").Value = s(0)
Range("C5").Value = s(1)
Range("D5").Value = s(2)
Range("E5").Value = s(3)
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


Just as an additional note (I hit send too quickly), the Split function, as a
default, will use <space as the delimiter and also return all of the strings,
so the following routine is equivalent and a bit shorter:

===============================================
Option Explicit

Sub ParseString()
Dim rSrc As Range
Dim rDest As Range
Dim Temp As Variant
Dim i As Long

Set rSrc = Range("A4")
Set rDest = Range("B5")

Temp = Split(rSrc.Text)

For i = 0 To UBound(Temp)
rDest.Offset(0, i).Value = Temp(i)
Next i

End Sub
================================================
--ron
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Split string into seperate cells

On Fri, 13 Apr 2007 08:03:40 -0400, Ron Rosenfeld
wrote:

On Fri, 13 Apr 2007 03:19:51 -0700, Les Stout wrote:

Hi Keri, try this

Sub single_Split()
'
Dim x As String, s As Variant

x = Range("A4")
s = Split(x, " ")
Range("B5").Value = s(0)
Range("C5").Value = s(1)
Range("D5").Value = s(2)
Range("E5").Value = s(3)
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


Just as an additional note (I hit send too quickly), the Split function, as a
default, will use <space as the delimiter and also return all of the strings,
so the following routine is equivalent and a bit shorter:

===============================================
Option Explicit

Sub ParseString()
Dim rSrc As Range
Dim rDest As Range
Dim Temp As Variant
Dim i As Long

Set rSrc = Range("A4")
Set rDest = Range("B5")

Temp = Split(rSrc.Text)

For i = 0 To UBound(Temp)
rDest.Offset(0, i).Value = Temp(i)
Next i

End Sub
=============================================== =
--ron



This is out of order and should be a followup response to keri's post.
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to split number and text string to separate cells? Lai704 Excel Discussion (Misc queries) 4 September 29th 08 02:18 AM
Seperate cell string into individual cells ERudy Excel Worksheet Functions 2 May 12th 06 07:43 AM
Split Cell Into Seperate Rows Andibevan[_4_] Excel Programming 2 December 20th 05 06:35 PM
Seperate/Split celinput peter Excel Worksheet Functions 2 August 6th 05 08:41 AM
Need to convert text string to seperate cells Debbie Nuding Excel Worksheet Functions 2 December 6th 04 06:14 PM


All times are GMT +1. The time now is 06:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"