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 / November 2006

Tip: Looking for answers? Try searching our database.

help please! - Search multiple spreadsheets for a worksheet name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SteveH - 06 Nov 2006 18:28 GMT
Sorry already posted something similar but I don't think I have been
very clear so here goes again.

I have a master spreadsheet containing lots of worksheets. Each
worksheet holds performance data for specfic fund and each worksheet is
named with the funds shortname.

I have a number of fund spreadsheets in residing in one directory each
with the long name for that fund and containing static fund data.
Within each fund spreadsheet there is a worksheet named after the fund
shortname (as in the master spreadsheet).

For each worksheet in the master spreadsheet I need to find the
matching worksheet in the correct fund spreadsheet and copy the data
across. This means copying about 20sets of data from seperate
worksheets in the master spreadsheet into the worksheet of the correct
fund spreadsheet. Each time the range of data to be copied is B2:D65.

Hope this makes sense and I hope you can help me!

Steve
Ron de Bruin - 06 Nov 2006 18:36 GMT
Ok, I understand you now
I will post a example for you after drinking coffee

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Sorry already posted something similar but I don't think I have been
> very clear so here goes again.
[quoted text clipped - 17 lines]
>
> Steve
Ron de Bruin - 06 Nov 2006 18:58 GMT
Ok Steve try this macro with function

It will open all files in the folder C:\Data and  loop through all sheets in each workbook
If the sheet exist in the basebook(workbook with the code) it will copy the range
B2:D65 from the basebook into mybook in B2 ?

Let me know if this is what you want

Sub Copyrange_2()
   Dim MyPath As String
   Dim FilesInPath As String
   Dim MyFiles() As String
   Dim Fnum As Long
   Dim mybook As Workbook
   Dim basebook As Workbook
   Dim sourceRange As Range
   Dim destrange As Range
   Dim sh As Worksheet

   'Fill in the path\folder where the files are
   MyPath = "C:\Data"    'or "\\Username\SharedDocs"
   'Add a slash at the end if the user forget
   If Right(MyPath, 1) <> "\" Then
       MyPath = MyPath & "\"
   End If

   'If there are no Excel files in the folder exit the sub
   FilesInPath = Dir(MyPath & "*.xls")
   If FilesInPath = "" Then
       MsgBox "No files found"
       Exit Sub
   End If

   On Error GoTo CleanUp
   Application.ScreenUpdating = False

   Set basebook = ThisWorkbook
   'Fill the array(myFiles)with the list of Excel files in the folder
   Fnum = 0
   Do While FilesInPath <> ""
       Fnum = Fnum + 1
       ReDim Preserve MyFiles(1 To Fnum)
       MyFiles(Fnum) = FilesInPath
       FilesInPath = Dir()
   Loop

   'Loop through all files in the array(myFiles)
   For Fnum = LBound(MyFiles) To UBound(MyFiles)
       Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
       For Each sh In mybook.Worksheets
           If SheetExists(sh.Name, basebook) Then
               Set sourceRange = basebook.Worksheets(sh.Name).Range("B2:D65")
               Set destrange = mybook.Worksheets(sh.Name).Range("B2")
               sourceRange.Copy destrange
           End If
       Next sh

       mybook.Close savechanges:=True
   Next Fnum

CleanUp:
   Application.ScreenUpdating = True
End Sub

Function SheetExists(SName As String, _
                    Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
   On Error Resume Next
   If WB Is Nothing Then Set WB = ThisWorkbook
   SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Ok, I understand you now
> I will post a example for you after drinking coffee
[quoted text clipped - 20 lines]
>>
>> Steve
SteveH - 06 Nov 2006 20:52 GMT
That is absolutely perfect, works a treat!

Thank you so much!!!!!!!

> Ok Steve try this macro with function
>
[quoted text clipped - 100 lines]
> >>
> >> Steve
Ron de Bruin - 06 Nov 2006 20:59 GMT
Hi Steve

>That is absolutely perfect, works a treat!

Great

Thanks for the feedback

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> That is absolutely perfect, works a treat!
>
[quoted text clipped - 104 lines]
>> >>
>> >> Steve

Rate this thread:






 
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.