VBA to Consolidate multiple files from Folder into 1 workbook and only copy certain worksheet with specific name from the excel files.

Jnt

New Member
Joined
Nov 25, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi all the macro expert,
I need to consolidate multiple files from 1 folder yet the each workbooks consists of 4-5 worksheets which I only need the data from 1 particular worksheets from each workbooks( the rest like index or other worksheet name will be excluded).
Currently I am using the below VBA to consolidate the file but it will also include all the worksheets into 1 workbooks which I do not really need all the worksheets into a workbooks. . Hence I would have to manually delete the worksheet one by one which time consuming. Can you help to look at my below VBA and help to edit or modify the code that can help me to exclude the certain worksheet name OR only include the worksheet name that I want. whichever way may help. Many Thanks

Sub CombineFiles()

Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim WS As Worksheet

Application.EnableEvents = False
Application.ScreenUpdating = False
Path = "C:\Users\jlsh\Documents\Power Query" 'Change as needed
FileName = Dir(Path & "\*.xls", vbNormal)
Do Until FileName = ""
Set Wkb = Workbooks.Open(FileName:=Path & "\" & FileName)
For Each WS In Wkb.Worksheets
WS.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next WS
Wkb.Close False
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
An alternative to VBA is Power Query

I tried to explore the power query before but couldn't work as all worksheet format somehow got different and was unable to group them together. Or maybe I m too dumb to understand through video.😂
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,530
Members
448,969
Latest member
mirek8991

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