Hi, I am a beginner in Excel VBA.
When I download an Excel report from my accounting system, it generates 2 extra empty sheets called "Sheet2" and "Sheet3". I only need "Sheet1". This repeats for all other 10 reports that I download from the system. What I need to do is to delete "Sheet2" and "Sheet3" from every downloaded report and combine these 10 reports into a single workbook. I have managed to find this merging workbooks VBA (see below). But am wondering how can I add in the step to delete "Sheet2" and "Sheet3"?
Sub ConslidateWorkbooks()
Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = Environ("userprofile") & "DesktopTest"
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 am open to other VBA code as well. Thanks!!
When I download an Excel report from my accounting system, it generates 2 extra empty sheets called "Sheet2" and "Sheet3". I only need "Sheet1". This repeats for all other 10 reports that I download from the system. What I need to do is to delete "Sheet2" and "Sheet3" from every downloaded report and combine these 10 reports into a single workbook. I have managed to find this merging workbooks VBA (see below). But am wondering how can I add in the step to delete "Sheet2" and "Sheet3"?
Sub ConslidateWorkbooks()
Dim FolderPath As String
Dim Filename As String
Dim Sheet As Worksheet
Application.ScreenUpdating = False
FolderPath = Environ("userprofile") & "DesktopTest"
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 am open to other VBA code as well. Thanks!!