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.

Combining Several Worksheet into one

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alegria4ever - 23 Jan 2007 03:42 GMT
I have over 30 excel worksheets that are:
1.  Password protected
2.  The sheet is also password protected
3.  Each worksheet contains only one tab call "All" and this tab is in
the same format and contains the same column in every sheet.
4.  It's located in the same folder

I need to write a macro that will open all these workbook in this
folder and combine the data into one new sheet with only one tab called
"All".  I am able to write the code to open all the workbook but am
having a difficult time figuring out how to copy only the cells with
data into the new workbook and then do the same with all 30 workbook.

I know I have seen this code floating around before but I am having a
hard time finding the right one that fits my needs. If anyone can
provide some help, I'd appreciate it.

Thank you in advance.
Roger Govier - 23 Jan 2007 07:37 GMT
Hi

Take a look at Ron de Bruin's site. There is lots of code there that can
be adapted to what you want.

Signature

Regards

Roger Govier

>I have over 30 excel worksheets that are:
> 1.  Password protected
[quoted text clipped - 15 lines]
>
> Thank you in advance.
alegria4ever - 23 Jan 2007 15:59 GMT
Thanks Roger!

I have modified the code but it still is not working right, it only
copies the data on the first workbook it opens and then it doesn't do
anything to the other workbook.  Can you tell me why the following code
isn't working?

Sub OpenAllWorkbooksInFolder()
Application.EnableEvents = False
Application.ScreenUpdating = False

Dim i As Integer
Dim MyPath As String
Dim SourceRcount As Long
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook

Set basebook = ThisWorkbook
MyPath = "C:\Test\"
rnum = 12

   With Application.FileSearch
       .LookIn = MyPath
       '* represents wildcard characters
       .FileType = msoFileTypeExcelWorkbooks
           If .Execute > 0 Then 'Workbook exists
               For i = 1 To .FoundFiles.Count
               Set mybook = Workbooks.Open(.FoundFiles(i),
Password:="password")
               Sheets("All").Unprotect Password:="password"
               Range("A11:X11").AutoFilter
               Columns("B:X").EntireColumn.Hidden = False
               Set sourceRange =
mybook.Worksheets("All").Range("B12:X" &
ActiveCell.SpecialCells(xlCellTypeLastCell).Row)
               SourceRcount = sourceRange.Rows.Count
               Set destrange =
basebook.Worksheets("Combined").Range("B" & rnum)
               ' This will add the workbook name in column Y if you
want
               basebook.Worksheets("Combined").Cells(rnum, "Y").Value
= mybook.Name
                       With sourceRange
                           Set destrange =
basebook.Worksheets("Combined").Cells(rnum, "B"). _

Resize(.Rows.Count, .Columns.Count)
                       End With
                       destrange.Value = sourceRange.Value
           rnum = rnum + SourceRcount
           mybook.Close savechanges:=False
               Next i
           Else 'There is NOT a Workbook
               MsgBox "The Workbook does not exist"
           End If
   End With
   Application.EnableEvents = True
   Application.

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.