+ Reply to Thread
Results 1 to 6 of 6

Update master file from different workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Update master file from different workbooks

    Hello,

    i will like to know if some one can help me, I have master file (workbook) and 20 workbooks for 20 employes. Alle have the same columns excepte the master have the column (employe name),i want update master file from all 20 workbooks.

    Master file

    Column 1 = Employes name column 2 = Requisition number column 3 = amount of the requisition

    Employe workbooks

    column 1 = Requisition number column 2 = amount of the requisition

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,950

    Re: Update master file from different workbooks

    Is all data to be copied from the Employee Workbooks located on Sheet1?
    Is the file name for the 20 employee workbooks EmployeeName.xls?
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-04-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update master file from different workbooks

    Quote Originally Posted by alansidman View Post
    Is all data to be copied from the Employee Workbooks located on Sheet1?
    Is the file name for the 20 employee workbooks EmployeeName.xls?
    Hello,

    Thanks for your reply.

    yes the 20 workbooks have only 1 sheet (sheet 1) and yes for each 20 xls file will be the name of each employee.

    thanks again

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,950

    Re: Update master file from different workbooks

    Try this code out and make sure to change the path in the appropriate line noted.

    Sub ABC()
        Dim sPath As String, sName As String
        Dim bk As Workbook, r As Range
        Dim wb As Workbook
        Set wb = Workbooks("Master.xls")
        Dim sh As Worksheet
         
        Application.ScreenUpdating = False
        Set sh = Sheets("Sheet1")
        'Change the next line to reflect the path on your computer.
        sPath = "C:\Documents and Settings\Alan M Sidman\Desktop\Test\"
        sName = Dir(sPath & "*.xls")
        Do While sName <> ""
            Set bk = Workbooks.Open(sPath & sName)
            Dim lr As Long
            lr = Range("A" & Rows.Count).End(xlUp).Row
            Set r = Range("A2:B" & lr)
            Dim lrM As Long
            wb.Activate
            lrM = Range("B" & Rows.Count).End(xlUp).Row
            r.Copy wb.Sheets("Sheet1").Range("B" & lrM + 1)
            wb.Sheets("Sheet1").Range("A" & lrM + 1) = Left(sName, Len(sName) - 4)
            bk.Close SaveChanges:=False
            sName = Dir()
        Loop
        Application.CutCopyMode = xlCopy
        Application.ScreenUpdating = True
        MsgBox ("Completed")
        
    End Sub
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Last edited by alansidman; 02-11-2014 at 04:53 PM.

  5. #5
    Registered User
    Join Date
    02-04-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update master file from different workbooks

    Quote Originally Posted by alansidman View Post
    Try this code out and make sure to change the path in the appropriate line noted.

    Sub ABC()
        Dim sPath As String, sName As String
        Dim bk As Workbook, r As Range
        Dim wb As Workbook
        Set wb = Workbooks("Master.xls")
        Dim sh As Worksheet
         
        Application.ScreenUpdating = False
        Set sh = Sheets("Sheet1")
        'Change the next line to reflect the path on your computer.
        sPath = "C:\Documents and Settings\Alan M Sidman\Desktop\Test\"
        sName = Dir(sPath & "*.xls")
        Do While sName <> ""
            Set bk = Workbooks.Open(sPath & sName)
            Dim lr As Long
            lr = Range("A" & Rows.Count).End(xlUp).Row
            Set r = Range("A2:B" & lr)
            Dim lrM As Long
            wb.Activate
            lrM = Range("B" & Rows.Count).End(xlUp).Row
            r.Copy wb.Sheets("Sheet1").Range("B" & lrM + 1)
            wb.Sheets("Sheet1").Range("A" & lrM + 1) = sName
            bk.Close SaveChanges:=False
            sName = Dir()
        Loop
        Application.CutCopyMode = xlCopy
        Application.ScreenUpdating = True
        MsgBox ("Completed")
        
    End Sub
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Many thanks

    i will try this evening,

    here is the exemple of two employes name johnsmith.xls and mariesmith.xls where I put this file in the code.

    thanks for your patience and your help

  6. #6
    Registered User
    Join Date
    02-04-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update master file from different workbooks

    I have tried the code yesterday:

    there is the result:

    Name of Officer Requisition # Amount
    johnsmith.xlsx 1 $11
    2 $22

    mariesmith.xlsx 3 $33
    4 $44


    johnsmith.xlsx 1 $11
    2 $22

    mariesmith.xlsx 3 $33
    4 $44


    The problem its if run the code twice time they creat another ligne for marie and john, wath I want its if john add another ligne when i run the code i want this line goes under is name and not creat again his name. The requisition number for sure will NEVER changed (the requisition number is the column B for the master file and column A for employe file) if a employe change the amount exemple for the requisition #4 i want the code update the new amount for the requisition #4 in the column C in the master file.

    ***Sorry my drawing look wrong***
    Last edited by ML69; 02-12-2014 at 02:04 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Update Multiple workbooks with master file
    By iwelcomesu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2013, 05:10 AM
  2. Replies: 0
    Last Post: 03-04-2013, 03:40 AM
  3. VBA code to update master file and reflect changes on other workbooks
    By Kimston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 08:56 AM
  4. Update cell values in master file if changes were made in update file
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-10-2012, 03:03 PM
  5. Update workbooks from a master
    By blue102040 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2005, 07:58 PM

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