Results 1 to 6 of 6

Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names

Threaded View

  1. #1
    Registered User
    Join Date
    07-31-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    7

    Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names

    Hello

    I found this code (Copy All Sheets From Each Workbook in Folder to a Single Sheet in New Workbook) and I'd like to use it to get monthly reports through several daily reports.


    Can someone help me to modify this code so that it shows the name of the workbook that the data has been derived from in a separate coloumn (r.g. column Z)?

    Also, the current code pastes the formulas and values, but I just need the values of the formulas not the actual formulas.

    And finally, I don't need the entire pages I just want to copy the cells A1:Y20 of each workbook.

    Thanks,
    Sub mcrOMACopyAllWbInFolderToActiveSheet()
    
        Dim cel As Range
        Dim FileName, ws As Worksheet
        Dim rng As Range
        Dim destWB As Workbook
        Dim pPath As String
        Dim ShellApp As Object
        
        ' Get user to select folder where the data you wish copied lies.
        Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, Prompt, 0, OpenAt)
         
        On Error Resume Next
            pPath = ShellApp.self.Path
        On Error GoTo 0
         
        ' everything happens in this block, first check to see if the folder where the data
        ' resides was selected, then open a new workbook, loop through all files in folder
        ' and all sheets within each file, copying them to the newly created workbook
        ' so the data can be formatted for reporting.
        Application.ScreenUpdating = 0
            If pPath = "" Then
            '  Cancel was selected
                MsgBox "Stopping because you did not select a Folder"
                Exit Sub
            End If
            LR = 1
            ' Add new workbook here
            Workbooks.Add
            Set destWB = ActiveWorkbook
                With CreateObject("scripting.filesystemobject")
                    ' Loop through all files in folder
                    For Each FileName In .getfolder(pPath).Files
                        With Workbooks.Open(FileName)
                            ' Loop through all worksheets in workbook
                            For Each ws In .Sheets
                                ws.UsedRange.Copy destWB.Sheets(1).Cells(LR, 1)
                                LR = destWB.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row + 2
                            Next
                            .Close True
                        End With
                    Next
                End With
            Application.ScreenUpdating = 1
    End Sub
    Last edited by Cutter; 09-21-2012 at 09:59 PM. Reason: Replaced QUOTE tags with CODE tags

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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