Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default I want to separate text at all the full stops

I know I can do this with text-to-columns, but I may have more than 256
strings in my text-file seperated by full stops, and I can't always use
2007.

What I need is a kind of 'Text-to-Rows' feature, so that it puts each string
into the next cell down

Is there an easy way to do this?

M

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default I want to separate text at all the full stops

One way:

Public Sub FullStopDelmitedTextToRows()
Const csDelim As String = "."
Dim vArr As Variant
Dim rCell As Range
With Selection
If .Rows.Count 1 Then
MsgBox "You must choose cells in one row only"
Else
For Each rCell In .Cells
With rCell
If Not IsEmpty(.Value) Then
vArr = Split(.Text, csDelim)
If IsArray(vArr) Then
With .Resize(UBound(vArr) - LBound(vArr) + 1, 1)
If Application.CountA(.Cells) 1 Then
MsgBox "Can only expand into empty cells"
Exit Sub
End If
.Value = Application.Transpose(vArr)
End With
Else
.Value = vArr
End If
End If
End With
Next rCell
End If
End With
End Sub

Note: Error checking is very minimal




In article ,
"Michelle" wrote:

I know I can do this with text-to-columns, but I may have more than 256
strings in my text-file seperated by full stops, and I can't always use
2007.

What I need is a kind of 'Text-to-Rows' feature, so that it puts each string
into the next cell down

Is there an easy way to do this?

M

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default I want to separate text at all the full stops

On Thu, 15 Jan 2009 16:10:09 -0000, "Michelle"
wrote:

I know I can do this with text-to-columns, but I may have more than 256
strings in my text-file seperated by full stops, and I can't always use
2007.

What I need is a kind of 'Text-to-Rows' feature, so that it puts each string
into the next cell down

Is there an easy way to do this?

M


This does literally what you request:

=================================
Option Explicit
Sub TextToRows()
Dim c As Range
Dim i As Long
Dim re As Object, mc As Object, m As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[^.]+"

For Each c In Selection 'or however you set up
'the range to process

If re.test(c.Value) = True Then
i = 2
Set mc = re.Execute(c.Value)
For Each m In mc
c(i, 1).Value = m.Value
i = i + 1
Next m
End If
Next c
End Sub
==================================

This is a little cleaner as it strips off the leading <space's that may be
between the "." and the next word:

================================
Option Explicit
Sub TextToRows()
Dim c As Range
Dim i As Long
Dim re As Object, mc As Object, m As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[^.]+"

For Each c In Selection 'or however you set up
'the range to process

If re.test(c.Value) = True Then
i = 2
Set mc = re.Execute(c.Value)
For Each m In mc
c(i, 1).Value = Trim(m.Value)
i = i + 1
Next m
End If
Next c
End Sub
===============================
--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
Adding periods (full stops) to the middle of numbers Derek M[_2_] Excel Worksheet Functions 7 May 15th 23 03:41 AM
separate two dates from a text string into two separate cells Tacrier Excel Discussion (Misc queries) 3 October 13th 08 08:53 PM
User Defined Functions to separate full names DZ Excel Programming 4 May 21st 08 08:43 PM
Matching CELL text (full word) to full word in string in another DShaw Excel Programming 7 September 12th 06 05:25 PM
How do i separate full names appearing in single cells? daveylee Excel Worksheet Functions 3 January 18th 06 09:51 PM


All times are GMT +1. The time now is 10:15 PM.

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

About Us

"It's about Microsoft Excel"