VB and VBA Users Source Code: Re: Return the part of a string up to a given character
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
VB/VBA Source Code
Re: Return the part of a string up to a given character
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, April 18, 2001
Hits:
717
Category:
Visual Basic General
Article:
A slightly quicker version of this routine would be: Sub Testdemo() Debug.Print ReturnSubString("TheStringGoesUpToHere_RestOftheString", "_", False) Debug.Print ReturnSubString("TheStringGoesUpToHere_RestOftheString", "_", True) End Sub 'Purpose : Returns a portion of a string based on the location of a sub string 'Inputs : sToSearch The string to return a portion of ' sToFind The string to find in sToSearch ' [bReturnLeft] If True returns the left portion of sToSearch ' else returns the right portion 'Outputs : The sub string 'Author : Andrew Baker (www.vbusers.com) 'Date : 25/11/2000 03:33 'Notes : 'Revisions : Function ReturnSubString(ByRef sToSearch As String, ByRef sToFind As String, Optional bReturnLeft As Boolean = True) As String Dim lPos As Long lPos = InStr(1, sToSearch, sToFind) If lPos Then If bReturnLeft Then ReturnSubString = Left$(sToSearch, lPos - 1) Else ReturnSubString = Mid$(sToSearch, lPos + Len(sToFind)) End If End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder