Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA 3

Status
Not open for further replies.

NWPA

MIS
Jan 20, 2005
8
US
Hello,
I have a question. I am trying to write a VBA function that will capture everything right of a "/" for example if i have the url. abc.biz/abc/preference/abc.php I want to capture everything right of the first "/" so my next cell shows abc/preference/abc.php I know i need to create a function seperating the "/" so I wrote.

Function FullExtension(sStr As String)
FullExtension = Split(sStr, "/")(LBound(Split(sStr, "/")) + 1)
End Function

This grabs abc but I want to capture everything right of the initial "/" and there is no way of determining how many "/" there are so I can't continue the function with +2, +3, +4 etc.

Any help would be appriciated.
 
FullExtension = Split(sStr, "/", 2)(1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV

I hope you don't mind if I ask a question about your response.

FullExtension = Split(sStr, "/", 2) I understand
FullExtension = Split(sStr, "/", 2)(1) I don't, can you explain?

 
Hi mscallisto,

Split returns a zero-based array.

The (1) at the end is just an index, returning element number one of the array (the last of two elements in this case), which is everything after the first "/".

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi,

With any array, you can determine the upper bound (the nth element) by using the UBound function.

for instance
Code:
for i = LBound(FullExtension) to UBound(FullExtension)
  msgbox FullExtension(i)
next
would display each element in the array.

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Thanks to you all.
This really does reduce parsing code, and I imagine speed as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top