View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Find matching tab names between different workbooks

the following untested pseudo code should get you started:
Sub OpenFiles()
Dim sh as Worksheet, sh1 as Worksheet
dim bk as Workbook
Dim sName as String
Dim sPath as String
Dim bFound as Boolean
sPath = "C:\Myfiles\"
sName = Dir(sPath & "Data*.xls")
do while sName < ""
bFound = False
set bk = workbooks.open( sPath & sName)
for each sh in bk.worksheets
set sh1 = Nothing
On error resume Next
set sh1 = workbooks("Filter.xls").Worksheets(sh.name)
On Error goto 0
if not sh1 is nothing then
' copy from sh to sh1
bFound = True
else
' matching sheet not found
end if
Next sh
If not bFound then
msgbox "No match found in " & bk.name
end if
bk.close Savechanges:=False
sName = dir()
Loop
End Sub



--
Regards,
Tom Ogilvy


"Freddy" wrote:

I have a workbook (lets call it Filter.xls) containing several tabs with
different names, lets say: 111111, 222222, and 333333. The Filter.xls file
contains formulas which are applied to records of numerical data obtained
from separate works (lets call them Data1.xls, Data2.xls, Data3.xls, etc.)
containing several tabs with different names like 111111, xxxx, 222222, xxxx,
333333, xxxx. All aforementioned files would be in the same working folder.

What Id like the VBA code to do is to cycle through any existing
Data[#].xls files and check if there are matching tab names between them and
the Filter.xls file and, if so, copy the record set from the matching tab in
the Data[#].xls file to the matching tab in the Filter.xls file. I already
have code to copy the record set from the Data[#].xls file into the
Filter.xls file but what I am missing is the code that determines if there is
a match between the tabs in the Filter.xls file and any available Data[#].xls
file. If there is no match then notify the user and exit.

Id appreciate anyones assistance. Please contact me if you need further
details.