Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default extracting characters at a specified limit to seperate cells

On 22 Jan 2007 09:26:37 -0800, "tevid" wrote:

Ron I would like to then extract the remaining characters into another
cell


And what about having the break at a "logical point" (e.g. after the tilde?).

If the location of the break is not important, you can just extend Dave's
formula, perhaps with an error check when the formula returns a null string:

e.g. =IF(LEN(MID(A1,300,75))0,MID(A1,300,75),"")

If you want the break to be at the "tilde", then one way is using VBA to write
a User Defined Function using Regular Expressions.

For that:

<alt-F11 opens the VB Editor.
Ensure your project is highlighted in the Project Explorer window.
Insert/Module and paste the code below into the window that opens.
From the menu bar of the VB Editor: Tools/References and select "Microsoft
VBScript Regular Expressions 5.5" from the list of Available References.

Then, with your string in A1, enter this formula in some cell and drag across
as far (or further) than required to return the entire string:

=remid($A$1,"[\s\S]{1,74}~",COLUMNS($A:A))

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

Function REMid(str As String, Pattern As String, _
Optional Index As Variant = 1, _
Optional CaseSensitive As Boolean = True) _
As Variant 'Variant as value may be string or array

Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection

Dim i As Long 'counter

' Create a regular expression object.
Set objRegExp = New RegExp

'Set the pattern by using the Pattern property.
objRegExp.Pattern = Pattern

' Set Case Insensitivity.
objRegExp.IgnoreCase = Not CaseSensitive

'Set global applicability.
objRegExp.Global = True

'Test whether the String can be compared.
If (objRegExp.Test(str) = True) Then

'Get the matches.
Set colMatches = objRegExp.Execute(str) ' Execute search.

On Error Resume Next 'return null string if a colmatch index is non-existent
If IsArray(Index) Then
ReDim t(1 To UBound(Index))
For i = 1 To UBound(Index)
t(i) = colMatches(Index(i) - 1)
Next i
REMid = t()
Else
REMid = CStr(colMatches(Index - 1))
If IsEmpty(REMid) Then REMid = ""
End If
On Error GoTo 0 'reset error handler
Else
REMid = ""
End If
End Function

======================================
--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
Linking Groups of cells between workbooks vnacj-joe Excel Discussion (Misc queries) 4 June 14th 07 05:18 PM
"Weird" characters in cells GARY Excel Discussion (Misc queries) 3 December 2nd 06 03:36 PM
Calculating only non-empty cells... Jay Excel Worksheet Functions 9 September 22nd 06 03:20 AM
255 characters in cells David Perry Excel Discussion (Misc queries) 2 January 26th 05 01:31 AM
linking cells in Excel 2003. How to not truncate to 255 characters. GarryFerg Excel Discussion (Misc queries) 5 December 8th 04 03:33 PM


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