Results 1 to 7 of 7

Thread: Macro to transfer data from open workbook to closed workbook with accumulation

  1. #1
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0

    Macro to transfer data from open workbook to closed workbook with accumulation

    Hello pretty searched the web but could not find exactly accumulation. What's the question: I have a 30th workbooks and a single workbook. My point is this: in each of the 30 workbooks to put the macro (which will be the same) and the opening of the workbook I carry a specific cell in the general workbook, but the superposition (aggregation), ie if the first record was in cell C9, the next one is in C10 and so to the end. I'll attach an example that I did in a workbook, but the yellow cells relate to the transfer of information in the other (general) workbook.


    I found this macro, but it replaces only within the cells, and the idea is to make an entry in the next row and do not know how to do it.

    Code:
    Sub Macro1()
    
    Dim wbTo As Workbook, wbFrom As Workbook
    
    Application.ScreenUpdating = False
    
    'Change path below
    Set wbFrom = ThisWorkbook
    Set wbTo = Workbooks.Open("C:\Documents and Settings\Stephen\Desktop\goodbye.xlsx")
    
    With wbTo
        .Sheets(1).Range("A1") = wbFrom.Sheets(1).Range("A3")
        .Sheets(1).Range("A2") = wbFrom.Sheets(1).Range("D6")
        .Sheets(1).Range("A3") = wbFrom.Sheets(1).Range("F9")
        .Sheets(1).Range("A4") = wbFrom.Sheets(1).Range("I6")
        .Sheets(1).Range("A5") = wbFrom.Sheets(1).Range("K10")
        .Sheets(1).Range("A6") = wbFrom.Sheets(1).Range("I18")
        .Close True
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    1Book1.xlsx

  2. #2
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    12
    attach please a sample file with data and desired result (not an empty sheet)

  3. #3
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0
    OK attach sample numbers in 2 workbooks (yellow cells) and Workbook "Total" - in each of the workbooks yellow cells are the same: "B5" is "B5" - these documents are invoices and cells are totally same, the idea is when I open a (desired by me) invoice me carry the result of the numbers in the workbook "Total", if in one workbook in cell "D5" = 999999, then let me "paste special value" in the next available cell of the selected column, as in the case for "D5", and starts at column "B9" and down. This applies to all the yellow cells, and is exactly the same.
    So the macro will insert in each invoice, so I can activate it, eg a button. Once I open a (desired by me) invoice - I write what I write and push the button, then follow the macro to find the next available cell on the desired column sets the number.
    If there is something to make it easier, please ask. Thanks in advance.
    Attached Files Attached Files

  4. #4
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    12
    Code:
    Sub a()
    fname = "C:\TEST\total.xlsx" ' to be changed
    Set wbFrom = ThisWorkbook
    Set wbTo = Workbooks.Open(fname)
    Application.ScreenUpdating = False
    With wbTo
        LR = .Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row + 1
        .Sheets(1).Range("B" & LR) = wbFrom.Sheets(1).Range("D5")
        .Sheets(1).Range("C" & LR) = wbFrom.Sheets(1).Range("C51")
        .Sheets(1).Range("E" & LR) = wbFrom.Sheets(1).Range("H48")
        .Sheets(1).Range("F" & LR) = wbFrom.Sheets(1).Range("F29")
        .Sheets(1).Range("G" & LR) = wbFrom.Sheets(1).Range("A29")
        .Sheets(1).Range("H" & LR) = wbFrom.Sheets(1).Range("A30")
        .Sheets(1).Range("I" & LR) = wbFrom.Sheets(1).Range("B46")
        .Close True
    End With
    Application.ScreenUpdating = True
    End Sub

  5. #5
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Different angle. Only 1 macro in WB Total.
    On firing the code FilePicker will open, select desired invoice, invoice will open, numbers will be copied, invoice is closed.
    Code:
    Sub tst()
        With Application.FileDialog(msoFileDialogFilePicker)
            .Show
            Workbooks.Open .SelectedItems(1)
        End With
        Set wbTo = ThisWorkbook.Sheets("Total")
        With ActiveWorkbook
            With .Sheets(1)
                wbTo.Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(, 8) = Array(.Range("D5"), .Range("C51"), , _
                        .Range("H48"), .Range("F29"), .Range("A29"), .Range("A30"), .Range("B46"))
            End With
            .Close False
        End With
    End Sub
    Last edited by bakerman; 08-25-2013 at 10:49 AM.

  6. #6
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0
    Hello patel
    incredibly well done, I put my macro on each invoice and everything is transferred. Heartily thank you. Be alive and well.

    Hello bakerman
    In your case - were also very clever, but it complicates matters: what I mean - once I got to open my invoice and to write data to keep it, close it, then open the shared file to find desired invoice and Extract (transmit data). But it's interesting that I would use for another job. Thank you.

  7. #7
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    12
    very good bakerman !!!

Similar Threads

  1. Open And Activate Workbook Before Runing Macro
    By Howardc in forum Excel Help
    Replies: 5
    Last Post: 06-04-2013, 07:23 PM
  2. Replies: 0
    Last Post: 04-20-2013, 10:07 AM
  3. VBA Code to Open Workbook and copy data
    By Howardc in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 06:58 PM
  4. Update data from closed workbook with sumif formula
    By leopaulc in forum Excel Help
    Replies: 4
    Last Post: 11-02-2011, 02:58 AM
  5. Split Closed Workbook into Multiple Workbooks Using ADO
    By ramakrishnan in forum Excel Help
    Replies: 4
    Last Post: 10-02-2011, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •