I can't get my consolidation macro working

jamesplant77

New Member
Joined
Nov 13, 2015
Messages
4
Hi, I am really new to VBA and I have created a number of workbooks that Project Managers are required to complete and submit to a folder each month:

M:\Business Change - Projects\PMO\JAMES - TEST\Demand Management\Resource Forecasts

The only tab they are required to complete is the one titled FORECAST. Once all workbooks have submitted, I want to be able to run a macro that takes all data from row 6 onwards, in each workbook and paste to the open workbook from row A6 which is exactly the same layout as the individual workbooks.

I would also need the code to stop at the last row that contained data, then move onto the next workbook and then paste that data on the next empty row in the master. I have masses of MI that will be taken from the master sheet, so really need this to work.

I have pasted the headers that appear in the master and the workbooks below, headers are in cells A4, B4 etc and the data I need is in the range A6:BO6

ROLECOST P/DPROJECT NAMEPROJECT ID (COST CENTRE)STATUSNAME OF RESOURCEFTEJFMAMJJASOND
212022201922232022222121

<colgroup><col style="width: 158pt; mso-width-source: userset; mso-width-alt: 7716;" width="211"> <col style="width: 80pt; mso-width-source: userset; mso-width-alt: 3913;" width="107"> <col style="width: 209pt; mso-width-source: userset; mso-width-alt: 10203;" width="279"> <col style="width: 83pt; mso-width-source: userset; mso-width-alt: 4059;" span="2" width="111"> <col style="width: 188pt; mso-width-source: userset; mso-width-alt: 9179;" width="251"> <col style="width: 38pt; mso-width-source: userset; mso-width-alt: 1828;" width="50"> <col style="width: 32pt; mso-width-source: userset; mso-width-alt: 1536;" span="12" width="42"> <tbody>
</tbody>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This assumes that the code will be hosted by the master workbook.

Code:
Sub consolidate()
Dim wb As Workbook, sh As Worksheet, fPath As String, fName As String
fPath = "M:\Business Change - Projects\PMO\JAMES - TEST\Demand Management\Resource Forecasts\"
fName = Dir(fPath & "*.xl*")
    Do While fName <> ""
        Set wb = Workbooks.Open(fPath & fName)
        Set sh = wb.Sheets("FORECAST")
            If Application.CountA(ThisWorkbook.Sheets(1).Rows(6)) = 0 Then
                sh.UsedRange.Offset(5).Copy ThisWorkbook.Sheets(1).Range("A6")
            Else
                sh.UsedRange.Offset(5).Copy ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp)(2)
            End If
        wb.Close False
        fName = Dir
    Loop
End Sub

Copy this code to the standard code module 1 of the master workbook. The workbook should be saved as a macro enabled workbook (.xlsm) to preserve the code. Be sure you have set your security center settings to allow access to VBA and macros.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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