+ Reply to Thread
Results 1 to 20 of 20

Bringing data from mulitple worksheets to a master sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2007
    Posts
    60
    All the files will be stored in the same directory on our server.

    I am unable to attach the spread sheet - I keep getting an error (I have tried .xls & .zip)

    Basicaly row 1 is a header
    2 down will contain consistent data

    Coloumns A-Q are filled -

    Status, order date, customer, country, area, sales man, machine, quote price, etc.

    It is just data - Each spreadsheet will have no forumla just manually typed info.

    If you still need an example can you suggest a free file sharing website I can use?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You won't need to copy the header row, but what about the "consistent data"?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-22-2007
    Posts
    60
    Yeah don't need the header

    By consistent - I mean there will be no blank lines. until the end of the data.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You'll have to test this. The code first asks the user to select a Folder containing the files. Then copies the data from each workbook to the one containing the code.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-22-2007
    Posts
    60
    I just get a "no workbooks found" error.


    Other xls sheets will also be present in the folder that do not relate to this.

    I would prefer to hard code each file location into the script and have little or no user intervension - the spread sheet is opened - It gets all the data from the other spreadsheets - It sorts that data it shows the data.

    I understand this will need chaging when new salesman begin or someone leaves but I would prefer it that way
    Last edited by kgkev; 06-10-2008 at 10:23 AM.

  6. #6
    Registered User
    Join Date
    05-03-2008
    Posts
    57
    someone sent me this code to accomplish a similar goal. you may find it useful:

    assume 3 workbooks called bill, mary and arthur. each has a sheet called "1" [saves my typing!] and each has columns called Person Account Date and Value.

    In a fourth workbook use >data >import external data > new database query. select Excel files as the data source. Click on the SQL button and type..

    SELECT `'1$'`.Person, `'1$'`.Account, `'1$'`.Date, `'1$'`.Value
    FROM `C:\bill`.`'1$'` `'1$'`
    union all
    SELECT `'1$'`.Person, `'1$'`.Account, `'1$'`.Date, `'1$'`.Value
    FROM `C:\arthur`.`'1$'` `'1$'`
    union all
    SELECT `'1$'`.Person, `'1$'`.Account, `'1$'`.Date, `'1$'`.Value
    FROM `C:\mary`.`'1$'` `'1$'`

  7. #7
    Registered User
    Join Date
    06-08-2008
    Posts
    36
    Hi royUK,
    I open your file, but there don't seems to be any place for me to select files.


    Hi durandal05,
    Where do I find this
    Click on the SQL button and type..
    I'm facing the same problem as kgkev. Attached is the objective that I want to acheieve. Combine book1 and book2 to from combined book.
    Attached Files Attached Files

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by kgkev
    I just get a "no workbooks found" error.


    Other xls sheets will also be present in the folder that do not relate to this.

    I would prefer to hard code each file location into the script and have little or no user intervension - the spread sheet is opened - It gets all the data from the other spreadsheets - It sorts that data it shows the data.

    I understand this will need chaging when new salesman begin or someone leaves but I would prefer it that way
    If the folder you select contains excel files they will be opened and if they contain data it will be copied.

    To hard code the path you only need this macro

    Sub Get_Data_From_All()
        Dim wbSource As Workbook
        Dim wbThis As Workbook
        Dim rToCopy As Range
        Dim uRng   As Range
        Dim rNextCl As Range
        Dim lCount As Long
        Dim bHeaders As Boolean
    
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
    
            On Error Resume Next
    
            Set wbThis = ThisWorkbook
            'clear the range except  headers
            Set uRng = wbThis.Worksheets(1).UsedRange
            If uRng.Cells.Count <= 1 Then
                'no data in master sheet
                bHeaders = False
                GoTo search
            End If
            uRng.Offset(1, 0).Resize(uRng.Rows.Count - 1, _
                                     uRng.Columns.Count).Clear
                                     
    search:
            With .FileSearch
                .NewSearch  
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
               'change this path  
                .LookIn = "C:/MyFolder" 
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .FileType = msoFileTypeExcelWorkbooks
    
                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 wbSource = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                        Set rToCopy = wbSource.Worksheets(1).UsedRange
                        Set rNextCl = wbThis.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
                        If bHeaders Then
                            'headers exist so don't copy
                            rToCopy.Offset(1, 0).Resize(rToCopy.Rows.Count - 1, _
                                                        rToCopy.Columns.Count).Copy rNextCl
                            'no headers so copy
                            'place headers in Row 2
                        Else: rToCopy.Copy Cells(2, 1)
                            bHeaders = True
                        End If
                        wbSource.Close False     'close source workbook
                    Next lCount
                Else: MsgBox "No workbooks found"
                End If
            End With
    
    
            On Error GoTo 0
            .ScreenUpdating = True
            .DisplayAlerts = True
            .EnableEvents = True
        End With
    End Sub
    Last edited by royUK; 06-23-2008 at 12:31 PM.

  9. #9
    Registered User
    Join Date
    11-22-2007
    Posts
    60
    Nearly there now I think - But it only gets the data from one workbook.

    I have cheated and stored 3 sample enquiry logs in C:\myfolder

    I then run the macro from MASTERSHEET on my desktop.


    the problem I can see is the folder will contain excel files that do not contain the correct data and should not be carried across - As the file location is decided by our CRM it is not possible to change.

+ 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