Consolidate Workbook

mwexcel54321

New Member
Joined
Jan 5, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am looking to cycle through all workbooks in a folder and move/copy all of the files with the same name. For example, in the picture below, I would like to go through Test 1 - 3 and pull a tab named "TEST" into one workbook.

1641402217798.png


Sub ConslidateWorkbooks()

Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = Environ("userprofile") & "\Desktop\Test\"
Filename = Dir(FolderPath & "*.xls*")
Do While Filename <> ""
Workbooks.Open Filename:=FolderPath & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
Application.ScreenUpdating = True
End Sub

I have this sos far but it's not as dynamic and easy to use as I'd hoped.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

JEC

Well-known Member
Joined
Aug 21, 2021
Messages
1,057
Office Version
  1. 365
Platform
  1. Windows
Are you pasting all sheets of the Test files in 1 workbook?
 

JEC

Well-known Member
Joined
Aug 21, 2021
Messages
1,057
Office Version
  1. 365
Platform
  1. Windows
Alright, if you run this macro you can go to a folder and select the files from which you want to copy your sheets into your source file.
So in this case you select test1, test2 and test3.
Give it a try.

Note: you can multiselect your files in the explorer

VBA Code:
Sub jec()
 Dim c00, it As Variant, sh As Worksheet
 Application.ScreenUpdating = False
 
 With Application.FileDialog(msoFileDialogFilePicker)
   .AllowMultiSelect = True
    If .Show Then
       For Each it In .SelectedItems
          With GetObject(it)
            For Each sh In .Sheets
              sh.Copy , ThisWorkbook.Sheets(1)
            Next
           .Close 0
         End With
      Next
    End If
 End With
End Sub
 

JEC

Well-known Member
Joined
Aug 21, 2021
Messages
1,057
Office Version
  1. 365
Platform
  1. Windows
I forgot to delete c00 at the declaration at top. You could remove that variable.
 

Forum statistics

Threads
1,176,507
Messages
5,903,450
Members
435,030
Latest member
zechariah

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
Top