Find a Pattern and Parse Text
On Fri, 20 Aug 2010 12:44:26 -0700 (PDT), ryguy7272
wrote:
I’m looking for
something like this:
8834310G10X09999.xls
Checked Out To: COLE, TIMMY
Basically, this is the text ‘Checked Out To:’ and the name of the
Excel file.
The name of the Excel file comes from he
activeWB = strFullString & ".xls"
I need to think about this a bit. If you come up with something else
in the meantime, please do post back.
Thanks!!
As I alluded to in my previous post, in order to locate specific data,
you need to be specific in your description; AND your description
needs to be unambiguous.
In the example you give, you show only two lines
Line 1 contains ONLY an excel file name with a .xls suffix
Line 2 starts with "Checked Out To:" and ends with a name that
is all in capitals, but may include spaces and a comma.
Is that how these entries will always appear within my_var? And will
they always be on two consecutive lines with nothing else on those
lines?
Will there always be just a single entry in my_var, or can there be
multiple entries and a need to extract all of them?
Here's a code snippet that might pull out what you need, if my
assumptions are valid, but will return NOTHING if they are not.
In this case, my_var is the contents of A3, but you can change that to
inner.text or something similar.
==============================
Option Explicit
Sub GetCheckedOut()
Dim re As Object, mc As Object, m As Object
Dim my_var As String
Const sPat As String = _
"\b\w+\.xls[\s\S]+?Checked Out To:[\sA-Z,]+\b"
my_var = Range("$A$3").Text
Set re = CreateObject("vbscript.regexp")
re.Pattern = sPat
re.Global = True
re.ignorecase = False
If re.test(my_var) = True Then
Set mc = re.Execute(my_var)
For Each m In mc
Debug.Print m
Next m
End If
End Sub
=============================
|