+ Reply to Thread
Results 1 to 2 of 2

Consolidate Multiple Worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    06-10-2008
    Posts
    26

    Consolidate Multiple Worksheets

    Hello all,

    After reviewing the forum I have found code that I can modify to consolidate sheets within a given folder, although it will select all Excel files.

    I have also located code that can multi-select worksheets and open them. I just need to merge the two but do not know how.

    I'd like to select multiple worksheets in a dialog box (GetOpenFileName), etc, then consolidate them to my "Consolidated" worksheet in the active workbook.

    The code I found is as follows:

    Open multiple files:

    Sub OpenMultipleFiles()
    Dim fn As Variant, i As Integer
    fn = Application.GetOpenFilename("Excel-files,*.xls", 1, "Select One Or More Files To Open", , True)
    If TypeName(fn) = "Boolean" Then Exit Sub
    For i = 1 To UBound(fn)
    Debug.Print "Selected file #" & i & ": " & fn(i)
    
    
    'put your code to manipulate the text here
    
    Next i
    
    End Sub
    Consolidate sheets in a given directory:

    Sub CollateReportFromFiles()
    'Open all .XLS in specific folder (2007 compatible)
    Dim strFileName As String, strPath As String, MyVal As String
    Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet
        
    Application.EnableEvents = False
    Application.DisplayAlerts = False
        
    Set wbkNew = ThisWorkbook
    strPath = "C:\Documents and Settings\"
    strFileName = Dir(strPath & "*.xls")
    wbkNew.Activate
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp"
    
        For Each ws In Worksheets
            If ws.Name <> "Temp" Then ws.Delete
        Next ws
    
    ActiveSheet.Name = "Final"
    
        Do While Len(strFileName) > 0
            Set wbkOld = Workbooks.Open(strPath & strFileName)
            MyVal = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
            wbkOld.Sheets(MyVal & ".xdo").Activate
            'Copy After:=wbkNew.Sheets(Sheets.Count)
            ActiveSheet.Copy After:=wbkNew.Sheets(wbkNew.Sheets.Count)
            strFileName = Dir
            wbkOld.Close False
        Loop
        
    wbkNew.Sheets("Final").Delete
    Application.DisplayAlerts = False
    Application.EnableEvents = True
    End Sub
    Where am I to start on this one?

    Thank you for your help!

  2. #2
    Registered User
    Join Date
    06-10-2008
    Posts
    26

    Re: Consolidate Multiple Worksheets

    Does anyone know another way to combine the two codes?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1