Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following simple code:
sTxt = Mid(sSentence, 14, 5) This code copies 5 characters from the string contained in the variable "sSentence", starting at position 14. My question is, is there another way to do the same exact thing WITHOUT using the "Mid()" function??? I'm basically trying to find other ways to extract substrings without using the MID() function. Thank you! Robert Crandal |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Fri, 15 Apr 2011 01:45:00 -0700, "Robert Crandal" wrote:
I have the following simple code: sTxt = Mid(sSentence, 14, 5) This code copies 5 characters from the string contained in the variable "sSentence", starting at position 14. My question is, is there another way to do the same exact thing WITHOUT using the "Mid()" function??? I'm basically trying to find other ways to extract substrings without using the MID() function. Thank you! Robert Crandal Here are several methods ===================== Option Explicit Sub foo() Const S As String = "Now is the time for all" Debug.Print Mid(S, 14, 5) 'Use combination of Left and Right Debug.Print Left(Right(S, Len(S) - (14 - 1)), 5) 'Using nested worksheet function REPLACE With WorksheetFunction Debug.Print .Replace(.Replace([A1], 1, 13, ""), 5 + 1, 99, "") End With 'Using regular Expressions Dim re As Object Set re = CreateObject("vbscript.regexp") re.Pattern = "^[\s\S]{13}([\s\S]{5})[\s\S]*" Debug.Print re.Replace(S, "$1") Debug.Print vbLf End Sub ========================== |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Open Userform two ways | Excel Programming | |||
The error of my ways. | Excel Discussion (Misc queries) | |||
different ways to copy a range? | Excel Programming | |||
Ways of Summarising data | Excel Discussion (Misc queries) | |||
Ways to activate a macro | Excel Discussion (Misc queries) |