Looking up a partial filename

J

japper

Hi all,

I'm trying to set up a macro that grabs data from a secondar
spreadsheet. Unfortunately this spreadsheet changes the last 2 digit
of it's name each day.

Is there a simple way to only search for, say, the first 4 letters of
filename?

The file is called, 'Perf Anaysis 49' or 'Perf Analysis 50' etc.

Your help would be great

Cheer
 
B

Bob Phillips

Japper,

You could loop through the worksheets collection comparing the n left-most
characters against the known name part until you find a match. Will work as
long as there are two similarly named sheets.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
J

japper

Thanks....

That's sorted it...

Now- next question- how would you enter into the Visual Basi
Editor???

Cheer
 
C

Chip Pearson

Try something like the following:


Dim WB As Workbook
For Each WB In Workbooks
If WB.Name Like "Perf Analysis*" Then
Exit For
End If
Next WB

If Not WB Is Nothing Then
' do something with WB
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
J

japper

Thanks a lot guys- I'm well on the right path now.

Much appreciated.

Very useful site this- think I'll be dropping in quite ofte
 
Top