LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Parsing / seperating text string in excel cell

On Thu, 15 Nov 2007 15:52:02 -0800, sfleck
wrote:

I need to keep it in the same format as it needs to be entered into the
field with those seperators

What I am looking for I guess is to seperate out by 200 characters ensuring
that the 200th character was not going to cut a record in half


Here is a VBA user defined function that will parse out the segments of your
string. The arguments to the function are the string (or cell reference
containing the string); the maximum length that you want to have; and the Index
(or segment to return == e.g. 1,2,etc).

The string will not break at a separator; it also, as written, will not return
the final separator (but can if you want).

Using 89 for your sample string, the function will return the following (using
1,2,3,4 for Index):

262662,1;287740,1;266043,1;265832,1;283351,1;29886 4,1;292744,1;301754,1;302201,1;283346,1

296536,1;292910,1;274865,1;293748,1;77029,1;47952, 1;295392,1;292327,1;273352,1;276065,1

256396,1;269669,1;269671,1;82205,1;301349,1;269668 ,1;260051,1;81462,1;269670,1;302623,1

281220,1;297459,1;257806,1;271241

To enter the UDF, <alt-F11 opens the VB Editor.

Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code below into the window that opens.

To use it, enter a formula of the type:

=reparsestring($A$1,89,1) (returns the first max of 89 characters
=reparsestring($A$1,89,2) (returns the 2nd max of 89)

etc.

================================================== ========
Option Explicit
Function reParseString(str As String, MaxLength As Long, Index) As String
Dim re As Object
Dim mc As Object
Dim sPat As String
Dim sQuant As String

sQuant = "{1," & MaxLength & "}"
sPat = "([\s\S]" & sQuant & ")[,;]|$"

Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat

If re.test(str) = True Then
Set mc = re.Execute(str)
reParseString = mc(Index - 1).submatches(0)
End If

End Function
======================================

--ron
 
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
Parsing a text string into separate cells Bobalew Excel Worksheet Functions 1 June 6th 07 09:16 PM
seperating text in one cell to multiple cells Joe Excel Discussion (Misc queries) 13 January 27th 06 11:53 PM
help parsing multiple text sets from one cell [email protected] Excel Worksheet Functions 0 August 31st 05 05:17 PM
Seperating of Text in one cell into two columns Mistys template Excel Worksheet Functions 1 January 27th 05 04:06 PM
Parsing when deliminator is a string Rose Excel Worksheet Functions 5 December 14th 04 12:54 AM


All times are GMT +1. The time now is 11:44 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"