+ Reply to Thread
Results 1 to 6 of 6

Multiple excel files and collating specific cell info

Hybrid View

  1. #1
    Registered User
    Join Date
    09-20-2007
    Posts
    13

    Multiple excel files and collating specific cell info

    Hi,
    I have about 55 excel workbook templates (identical format; different info) from which I need to extract specific cells into a common worksheet to collate all the information. I have seen, in the past, a macro that lists the links to a specific cell in a number of workbooks saved in the same folder, once you have selected the folder where the workbooks are stored; Once the links are displayed you simply change the cell reference and copy/paste in the next column for all the others in same folder and hey presto you have the values for the same cell from all the templates. Has anyone come across this? Or help out in any way? Your help is very much appreciated
    Thanks

  2. #2
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Hi,

    See the attached file. It will pick up all data in cell B2 of every file in the same workbook as the active workbook is in.

    Let me know if you have any questions about this.

    Succes,
    Erik
    Attached Files Attached Files
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  3. #3
    Registered User
    Join Date
    09-20-2007
    Posts
    13
    Quote Originally Posted by WinteE
    Hi,

    See the attached file. It will pick up all data in cell B2 of every file in the same workbook as the active workbook is in.

    Let me know if you have any questions about this.

    Succes,
    Erik
    Hi Erik
    Thanks for your efforts but I cant seem to get it to work? You also say it will pick up cell b2 of every file in the same work book but I need to extract cells from a given same worksheet in multiple workbooks which are all stored in the same folder. I cant seem to view the code for this macro either when I hit alt+f11?
    Thanks
    Khuram

  4. #4
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Hi Khuram,

    In the code, which you'll find in the object 'ThisWorkbook', the following line has to be changed :

    ActiveSheet.Range("H" & counter).Value = "=+'" & ActiveWorkbook.Path & "\[" & f1.Name & "]Blad1'!$B$2"
    The part "Blad1" refers to the name of the sheet. "Blad1" is the Dutch version of the standard sheetname "Sheet1".

    Erik

  5. #5
    Forum Contributor
    Join Date
    08-10-2006
    Posts
    723
    hi ska.

    this code will need to be changed in the main code. put the path where all your workbookes are kepted.


    .LookIn = "C:\MyDocuments\TestResults"
    change this part of the code ie f5 to where the data is you want to copy from
    i have used 4 cells on my example
    add more for the more cells you have to copy

     rCell.Offset(2, 0).FormulaR1C1 = wbResults.Sheets(1).Range("f5")
    ub RunCodeOnAllXLSFiles()
        Dim lCount As Long
        Dim wbResults As Workbook
        Dim wbCodeBook As Workbook
        Dim rCell As Range
         
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.EnableEvents = False
         
        On Error Resume Next
         
        Set wbCodeBook = ThisWorkbook
         
        With Application.FileSearch
            .NewSearch
             'Change path to suit
              .LookIn = "C:\MyDocuments\TestResults"
            .FileType = msoFileTypeExcelWorkbooks
             '.Filename = "Book*.xls"
             
            If .Execute > 0 Then 'Workbooks in folder
                For lCount = 1 To .FoundFiles.Count 'Loop through all.
                     'Open Workbook x and Set a Workbook variable to it
                    Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                     
                     'DO YOUR CODE HERE
                    Set rCell = wbCodeBook.Sheets(1).Range("A65536").End(xlUp).Offset(1, 0)
                    
                    'THIS PUT THE NAME OF THE WORKBOOKS YOU ARE GETTING YOUR DATA FROM INTO A1
                  rCell.FormulaR1C1 = ActiveWorkbook.Name
                    
                    ' THIS PUTS THIS WILL PUT THE DATA IN ROW 1 COLUMN A,B,C,D, ETC AFTER GETTING IT FROM THE CELLS YOU SPECIFY
                    
    '
     
    
                    rCell.Offset(1, 0).FormulaR1C1 = wbResults.Sheets(1).rCell.Offset(1, 0)
                    rCell.Offset(2, 0).FormulaR1C1 = wbResults.Sheets(1).Range("f5")
                    rCell.Offset(0, 3).FormulaR1C1 = wbResults.Sheets(1).Range("f6")
                    rCell.Offset(0, 4).FormulaR1C1 = wbResults.Sheets(1).Range("f7")
                  
                    
                    
                    
                    wbResults.Close SaveChanges:=True
                     
                Next lCount
                
            End If
        End With
        ActiveWorkbook.Save
        On Error GoTo 0
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Application.EnableEvents = True
       
    End Sub
    hope this works
    this file will have to be in a different location to all the other files

    steve
    Last edited by stevekirk; 10-16-2007 at 12:58 PM.

  6. #6
    Registered User
    Join Date
    09-20-2007
    Posts
    13
    Hi Steve thanks for the reply and code, but I should have said I am a newbie at this.
    I copied the code and then tried changin the file path but am unsure as to what code you speak of when you say:
    'DO YOUR CODE HERE
    Set rCell = wbCodeBook.Sheets(1).Range("A65536").End(xlUp).Offset(1, 0)

    'THIS PUT THE NAME OF THE WORKBOOKS YOU ARE GETTING YOUR DATA FROM INTO A1
    rCell.FormulaR1C1 = ActiveWorkbook.Name
    Do i have to change the range A65536 to the deired cell or is that a limit of some sort?
    For the 2nd portion do I have to enter the active workbook name of all the template files I am extracting data from or the destination workbook (which I am assuming has to be open when the macro is run?

    also does this macro only work if all the work books are open i.e. can it not extract the data from each cell from closed workbooks?

    Sorry for all the questions your help is much appreciated

+ 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