Trim Between Characters

5 pts.
Tags:
Strings
SUBSTR
TRIM function
How do I Trim the text after a spcific character? (ie. www.website.com#http://www.website.com#) Trimed to www.website.com
ASKED: September 8, 2008  3:55 AM
UPDATED: September 8, 2008  4:41 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I am giving you a function having two arguments. 1. is the text to be trimmed, 2. is the specific character.
I think this will solve your problem.

</pre>
Public Function TrimedText(TextToTrim As String, SpecificCharacter As String) As String
TrimedText = “”
For i = 1 To VBA.Len(TextToTrim)
If VBA.Mid(TextToTrim, i, VBA.Len(SpecificCharacter)) <> SpecificCharacter Then
TrimedText = TrimedText & VBA.Mid(TextToTrim, i, 1)
Else
Exit For
End If
Next
End Function
<pre>

Try this in excel.
Start Excel, Tools Menu, Macro, Visual Basic Editor.
In Visual Basic Editor, Insert Menu, Module.
In Module, Copy and Paste above code. Save and close Visual Basic Editor.
In Excel, in cell ‘A1′ write your text string i. e. <b>www.website.com#http://www.website.com#)</b>, in cell ‘A2′ write the function <b>=TrimedText(A1,”#”)</b>.

You will get the solution.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following