Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Merge and update ???

Latest post Fri, Mar 25 2011 3:55 PM by Chris Downs. 5 replies.
  • Wed, Mar 23 2011 9:23 AM

    • sdc
    • Top 200 Contributor
    • Joined on Wed, Mar 23 2011
    • Posts 5
    • Points 105

    Merge and update ???

     Merge and update a main report

    I have 3 reports that get emailed out to 3 different companies, at the end of the day they fill out the reports and send back to me... what I am wanting to do in excel is when I get those individual reports I want to be able to merge and update the specific cells to the main report...
    Individual Reports
    EXAMPLE: Company A: 200 emp
    Company B: 15 Trained
    Company C: 25 ret
    MAIN Report:
    Company A: 20 emps (now I am wanting to merge and update Company A to 220 emp into main report)
    • Post Points: 37
  • Thu, Mar 24 2011 5:44 AM In reply to

    • Teppic_
    • Top 50 Contributor
    • Joined on Fri, Apr 3 2009
    • London UK
    • Posts 20
    • Points 228

    sdc,

    If the reports are in a fairly strict template format this is quite easily done with VBA.

    Try a sub something like the sub below as a starting point, put this in your MAIN workbook. It copys the data from Sheet1!E9 in an external workbook.

     

    Teppic_

    --------

    Sub Import_Data()
        Dim NewFN       As String
        Dim ControlFile As String
        Dim Cell_Ref    As String
       
        ControlFile = ActiveWorkbook.Name

        NewFN = Application.GetOpenFilename(FileFilter:="Excel File (*.xls), *.xls", Title:="Please select a file")
        If NewFN = "False" Then
            MsgBox "No Input File Selected"                     ' They pressed Cancel
            Exit Sub
        Else
            Workbooks.Open Filename:=NewFN
        End If
       
        ' this is  a bit crude for getting the workbook name...
        NewFN = Left(NewFN, InStrRev(NewFN, ".") - 1)       ' this may not work if the filename has more than on '.' char in it
        NewFN = Right(NewFN, Len(NewFN) - InStrRev(NewFN, "\"))
       
        Range("'[" + ControlFile + "]Sheet1'!E9").Clear
       
        Cell_Ref = "'[" + NewFN + "]Sheet1'!E9" ' copy the data
        Range(Cell_Ref).Copy
        Range("'[" + ControlFile + "]Sheet1'!E9").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
       
        Workbooks(NewFN & ".xls").Close   ' if file is not an xls this may want to be [xlsx, xlsm] etc
    End Sub

     

     

     

    Filed under:
    • Post Points: 21
  • Thu, Mar 24 2011 8:07 AM In reply to

    • sdc
    • Top 200 Contributor
    • Joined on Wed, Mar 23 2011
    • Posts 5
    • Points 105

    2 ?'s... do I need to rename my reports and also what is ment by strict formatting

     

    thx

    • Post Points: 21
  • Thu, Mar 24 2011 8:28 AM In reply to

    • Teppic_
    • Top 50 Contributor
    • Joined on Fri, Apr 3 2009
    • London UK
    • Posts 20
    • Points 228

    Sdc,

    No that macro would allow you to choose any input workbook - it will ask you which workbook when you run it.

    By strict formatting I mean it is going to make your life much easier if you know where to look for the data.

    It is possible to create a template so that the user will always put there content is specfic cell ranges, and on sheets whose name you know. If the people who send you reports are able to rename sheets and/or insert rows/columns then you might have a nightmare in getting a macro to find the data you want to copy across.

    Teppic_

    • Post Points: 21
  • Fri, Mar 25 2011 3:07 PM In reply to

    • sdc
    • Top 200 Contributor
    • Joined on Wed, Mar 23 2011
    • Posts 5
    • Points 105

    have another ?

    Hello I have this code and now I want to work it for each of my employees 4-2000, can anyone help here is the code

    Sub MoveDate()

    Select Case Range("AI3").Value
    Case Is = ""
    Range("Z3:AA3").Select
    Selection.Cut
    Range("AI3").Select
    ActiveSheet.Paste

    Case Else

    Range("AI3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Range("AK3").Select
    ActiveSheet.PasteSpecial Format:=12, Link:=1, DisplayAsIcon:=False, _
    IconFileName:=False

    Range("Z3:AA3").Select
    Selection.Cut
    Range("AI3").Select
    ActiveSheet.Paste
    End Select
    End Sub


    1: tryin to make this script autorun as soon as I open the worksheet?

    (i have tried changing the code to Private Sub Workbook_Open() but still will not work )

    2. have a list of employees 4-2000 I need this code to work for each employee


    any help would be appreciated
    thx

    • Post Points: 5
  • Fri, Mar 25 2011 3:55 PM In reply to

    Not a direct answer to your question, but Access 2007 and 2010 have an email data collection feature that is designed to do just this sort of thing, so you might want to try that. You can link to Excel worksheets from Access, so that might be an option for getting the data into the Access environment.

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.