VB and VBA Users Source Code: Return the part of a string up to a given character
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Return the part of a string up to a given character
By:
Arnaud
Email (spam proof):
Email the originator of this post
Date:
Wednesday, April 18, 2001
Hits:
830
Category:
Visual Basic General
Article:
Option Explicit ' Goes through each character of the string until a given character is found ' then it returns the substring to the given character Function ReturnSubstr(ByVal sToSearch As String, ByVal cToFind As String) As String ' inputs: sTosearch which is the string to search ' cToFind which is the character you want to find ' outputs: The part of the string to the given character in lower case ' Author: Arnaud Limbourg ' Date created: 18 april 2001 ' Date revised: 18 april 2001 Dim i As Long For i = 1 To Len(sToSearch) If i <> 1 Then If Right(Left(sToSearch, i), 1) = cToFind Then ReturnSubstr = LCase$(Left(sToSearch, i - 1)) Exit For End If End If Next End Function Sub testdemo() Debug.Print ReturnSubstr("TheStringGoesUpToHere_RestOftheString", "_") End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder