Results 1 to 9 of 9

Excel VBA copying data from closed workbooks with multiple different pathways

Threaded View

  1. #1
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    78

    Excel VBA copying data from closed workbooks with multiple different pathways

    Hello,

    The below code works for summing column C in the closed workbooks and dividing by 2 and pasting the data into the current workbook with the macro. I am needing to manipulate the formula so it can go into multiple pathways instead of all workbooks being located under the same pathway. Is there a way I can have the folder pathway reference a column (a cell for each pathway, i.e., G1, G2, G3, G4) in the worksheet, so then I can just change the pathway if needed in Excel and then the Macro will reference that for pulling the data?

    This code assumes all workbooks are in same folder.
    Sub CopyWorkbookData()
        Dim wbNames, i As Long
        Const ws As String = "Trial Balance"
        Const myDir As String = "c:\Users\rhoover\"
        wbNames = Array("Cudahy Center 06.17.xlsx", "Wellington Park 06.17.xlsx", "Wausau 06.17.xlsx", "Forest Plaza 06.17.xlsx")
        For i = 0 To UBound(wbNames)
            Cells(i + 1, 1).Formula = "=sum('" & myDir & "[" & wbNames(i) & "]" & ws & "'!c:c)/2"
        Next
    
        Range("A1:A4").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        
        Range("A1:A4").Select
        Selection.Style = "Comma"
        Range("A1").Select
    
    End Sub
    I tried below, but I get an error.
    Sub CopyWorkbookData()
        Dim wbNames, i As Long
        Const ws As String = "Trial Balance"
        Const myDir As String = "N:\Team-ASClientAcctgMIN\Team-Accounting\Property Archive\Slate Properties\Properties\GAR\Cudahy\Financial Reporting\2017\ERN001 - 06.17\Reporting\" & "N:\Team-ASClientAcctgMIN\Team-Accounting\Property Archive\Slate Properties\Properties\SUSO 4\Forest Plaza\Financial Reporting\2017\FTM001 - 06.17\Reporting\" & "N:\Team-ASClientAcctgMIN\Team-Accounting\Property Archive\Slate Properties\Properties\SUSO 3\Wausau\Financial Reporting\2017\FLT001 - 06.17\Reporting\" & "N:\Team-ASClientAcctgMIN\Team-Accounting\Property Archive\Slate Properties\Properties\SUSO 4\Wellington Park\Financial Reporting\2017\FSA001 - 06.17\Reporting\"
        
        wbNames = Array("Cudahy Center 06.17.xlsx", "Wellington Park 06.17.xlsx", "Wausau 06.17.xlsx", "Forest Plaza 06.17.xlsx")
        For i = 0 To UBound(wbNames)
            Cells(i + 1, 2).Formula = "=sum('" & myDir & "[" & wbNames(i) & "]" & ws & "'!c:c)/2"
        Next
    
        Range("A1:A4").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
        
        Range("A1:A4").Select
        Selection.Style = "Comma"
        Range("A1").Select
    
    End Sub
    Last edited by Hoover5896; 07-10-2017 at 03:30 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying specific cells from different closed workbooks to a Master Excel file
    By kennad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2015, 09:34 AM
  2. Copying data from a master worksheet to a folder full of closed workbooks
    By Simsam_g in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2015, 04:20 AM
  3. Copying specific data ranges from multiple (closed or in use by others) workbooks
    By TheRetroChief in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2014, 10:39 AM
  4. Copying rows from multiple closed workbooks to active workbook
    By onbeillp111 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2013, 11:19 AM
  5. [SOLVED] Copying cells from multiple closed workbooks to active workbook
    By Anonym216 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 07:53 AM
  6. VBA: Copying data from closed workbooks
    By staffordalex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2008, 01:20 PM
  7. Copying data from closed Workbooks
    By danman1043 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2008, 09:11 AM

Tags for this Thread

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