Info fed from various workbooks to one overview

28creation

Board Regular
Joined
Oct 13, 2014
Messages
124
Hi all,

I've got one overview workbook & several individual workbooks.

I want certain information to feed through to the overview book. I know how to do this but there's a few other bits I want to do....


I want four cells worth of information fed through from workbook #1 & the overview to have the name of workbook #1 (minus the file type) in another cell next to these four cells.

Then as info is fed into the individual workbooks the overview receives the info & adds it below the ones already received, with the name of the relevant file next to it.

Is there any way of doing this either through normal Excel means or with VBA?


Hope you can help.

Thanks, Matt
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I've had to remove one file from one folder & two files from another folder to get the relevant Team Overview to run the macro correctly.

Any idea what's causing these particular files to cause a problem?
 
Upvote 0
Is there anything particularly different about those three workbooks? Are they shortcuts, protected files, or different file types?
 
Upvote 0
Is there anything particularly different about those three workbooks? Are they shortcuts, protected files, or different file types?

No, they're all the same. I've discovered two or three more that are causing problems too, so I've removed them from that folder for the time being.
 
Upvote 0
I honestly don't know what is amiss. It could be that the "Workbooks.Open" line needs to be tweeked or maybe the server partition has some errors or settings that are causing the problem. I'm afraid my expertise is only Excel. Without seeing and working with your environment directly, it would probably take another few months to work the issues.

This bit of code should allow you to run the macro and it will skip over 1004 error and let you know what wasn't imported. As before, it's untested since I cannot replicate the errors on my side.

Code:
Option Explicit
Sub Run_Update()
    Dim mainReport As Workbook
    Dim arrEmp() As Variant
    Dim oFile As String
    Dim sErrMSB As String
    Dim finalRow As Long
    Dim i As Long
    Dim n As Long
    
    Application.ScreenUpdating = False 'Turn off screen updating to speed up macro

    ReDim arrEmp(4, 0)
    
    ChDrive "P:"
    ChDir "[COLOR=#333333]P:\Coaching\Schemes - Denah[/COLOR]"

    'Change this line to the directory that contains the workbooks
    oFile = Dir("[COLOR=#333333]P:\Coaching\Schemes - Denah[/COLOR]\*.xlsm")


    'Load workbook object of Overview workbook into variable
    Set mainReport = Application.Workbooks("Team Overview.xlsm")

    'Find the last used row in column B and load to variable
    finalRow = Cells(Rows.Count, 2).End(xlUp).Row
    
    'Delete the old data in the Overview workbook
    If finalRow > 7 Then Range("B8:J" & finalRow).Value = ""

    'Start Looping through all files in the directory
    Do While oFile <> ""
        On Error GoTo Trap
        If Right(oFile, Len(mainReport.Name)) <> mainReport.Name Then
            Workbooks.Open Filename:=oFile, UpdateLinks:=False, ReadOnly:=True 'Open file
            finalRow = Workbooks(oFile).Sheets("Feedback Log").Cells(Rows.Count, 2).End(xlUp).Row 'Find last row in column B
            If finalRow > 7 Then
                If Not arrEmp(0, 0) = "" Then
                    ReDim Preserve arrEmp(4, UBound(arrEmp, 2) + finalRow - 7) 'Expand 2nd dimension of the array to hold the new data
                End If
                For i = 8 To finalRow 'Loop through the rows
                    arrEmp(0, n) = Left(Workbooks(oFile).Name, Len(Workbooks(oFile).Name) - 5)  'Load workbook name
                    arrEmp(1, n) = Workbooks(oFile).Sheets("Feedback Log").Range("B" & i).Value 'Load column B data in the row to array
                    arrEmp(2, n) = Workbooks(oFile).Sheets("Feedback Log").Range("D" & i).Value 'Load column D data in the row to array
                    arrEmp(3, n) = Workbooks(oFile).Sheets("Feedback Log").Range("F" & i).Value 'Load column F data in the row to array
                    arrEmp(4, n) = Workbooks(oFile).Sheets("Feedback Log").Range("H" & i).Value 'Load column H data in the row to array
                    If Err.Number = 0 Then n = n + 1 Else Err.Clear 'Increase the 2nd dimension counter for next row
                Next i 'Loop to next row/exit if no more rows
            End If
            Workbooks(oFile).Close SaveChanges:=False 'Close the employee workbook
        End If
Skip:
        oFile = Dir
    Loop
    
    On Error GoTo 0
    Application.ScreenUpdating = True 'Turn screen updating back on to see values being added to overview workbook
    
    n = 8 'Turn counter into row marker
    For i = LBound(arrEmp, 2) To UBound(arrEmp, 2) 'Loop through the array and unload the data to the Overview workbook row by row
        Cells(n, 2).Value = arrEmp(0, i)
        Cells(n, 4).Value = arrEmp(1, i)
        Cells(n, 6).Value = arrEmp(2, i)
        Cells(n, 8).Value = arrEmp(3, i)
        Cells(n, 10).Value = arrEmp(4, i)
        n = n + 1
    Next i

    If sErrMSB <> "" Then
        MsgBox "The following workbooks were not imported:" & vbCr & vbCr & sErrMSB & vbCr & "You'll need to add the Feedback manually to complete the compilation."
    Else
        MsgBox "All Feedback data has successfully been compiled."
    End If

    Exit Sub
Trap:
    If Err.Number = 9 Then
        Resume Next
    ElseIf Err.Number = 1004 Then
        sErrMSB = sErrMSB & oFile & vbCr
        GoTo Skip
    Else
        On Error GoTo 0
        Application.ScreenUpdating = True
        Resume
    End If
End Sub

This thread is so long that I doubt we'll get any assistance from other experts without starting a new thread.
 
Upvote 0
Hi, this works really well, I like the message coming up to show it's finished running. Nice touch!

A few worksheets continue to cause problems, not quite sure how or why. But many thanks for all your help.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top