Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2007

Tip: Looking for answers? Try searching our database.

Extracting name out of line

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gordon - 27 Jan 2007 23:37 GMT
I am copying a line off the web with 4 names in it, separated by
spaces (From 1 to 6 spaces).  I am trying to extract name 3 from the
line.  Tried split(Var, " ") however Name moves according to the space
between the names. Var(2) can be the Name or according to spaces
between names, Var(6)

Can you help me?

Thank you, Gordon
Ron Rosenfeld - 28 Jan 2007 01:41 GMT
>I am copying a line off the web with 4 names in it, separated by
>spaces (From 1 to 6 spaces).  I am trying to extract name 3 from the
[quoted text clipped - 5 lines]
>
>Thank you, Gordon

Here's an example using regular expressions.  The example extracts all of the
names, but if you just want name 3, then:

Debug.print colMatches(2)

(the count is zero-based)

===================================
Option Explicit

Sub ParseNames()
Const T As String = "Name1    Name2 Name3    Name4"
Dim i As Long

Dim objRe As Object
Dim colMatches As Object
Const Pattern As String = "\w+"

Set objRe = CreateObject("vbscript.regexp")
objRe.Global = True
objRe.Pattern = Pattern

If objRe.test(T) = True Then
Set colMatches = objRe.Execute(T)

For i = 0 To colMatches.Count - 1
Debug.Print colMatches(i)
Next i

End If

End Sub

==============================

For just Name 3,
--ron
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.