VBA for 5 files to Master

RR786

New Member
Joined
Mar 22, 2020
Messages
9
Office Version
  1. 2013
I have about 5 files with data in columns A through BU. All 5 files have different names but 'data' is in worksheet.

i need a VBA to consolidate the data thats re all different length but only keeping current title in the Master file called 'Master'


Trying to get a VBA code to:

1. Clear data from master file
2. Open each of the 5 files. (TASS, MUC, SAS etc) but common start is 'Underlying Bridge - '
3. copy columns row 2 to where ever the data goes to and then add additional from file 2,3,4 etc
3. paste data tab within master file.

Can this be done? Thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
this is what i have :

Run-time error '424;: Object Required

seems like it after the copy - its unable to paste

VBA Code:
Private Sub CommandButton1_Click()
Dim sh As Worksheet, wb As Workbook, fPath As String, fName As String
fPath = "M:\20-21\Business Planning\Budgets\"
Set sh = ThisWorkbook.Sheets("Data")
sh.UsedRange.Offset(1).ClearContents
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(fPath & fName)
            wb.Sheets("Data").UsedRange.Offset(1).Copy
            sh.Cells(Row.Count, 1).End(x1Up)(2).PasteSpecial xlPasteValues
            wb.Close False
        End If
        fName = Dir
    Loop
End Sub
 
Upvote 0
Delete the old code and use this one.

VBA Code:
Private Sub CommandButton1_Click()
Dim sh As Worksheet, wb As Workbook, fPath As String, fName As String
fPath = "M:\20-21\Business Planning\Budgets\"
Set sh = ThisWorkbook.Sheets("Data")
sh.UsedRange.Offset(1).ClearContents
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(fPath & fName)
            wb.Sheets("Data").UsedRange.Offset(1).Copy
            sh.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial xlPasteValues
            Application.CutCopyMode = False
            wb.Close False
        End If
        fName = Dir
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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