I am trying to add steps to my main merge VBA code, and I cannot find the solution.
this step to apply to the active workbook... (delete 3 sheets with names)
I need this next part to apply to ALL SHEETS in the active workbook
these 2 steps (add auto filter for row 1, freeze top row)
I have tried various things, and none are working.
Any help would be appreciated.
My main code is below
this step to apply to the active workbook... (delete 3 sheets with names)
VBA Code:
Sheets("Sheet1").Delete
Sheets("Sheet2").Delete
Sheets("Sheet3").Delete
I need this next part to apply to ALL SHEETS in the active workbook
these 2 steps (add auto filter for row 1, freeze top row)
VBA Code:
Rows("1:1").Select
Selection.AutoFilter
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
I have tried various things, and none are working.
Any help would be appreciated.
My main code is below
VBA Code:
Sub mergeFiles_v669()
'Merges all files in a folder to a main file.
'Define variables:
Dim numberOfFilesChosen, i As Integer
Dim tempFileDialog As FileDialog
Dim mainWorkbook, sourceWorkbook As Workbook
Dim tempWorkSheet As Worksheet
Set mainWorkbook = Application.ActiveWorkbook
Set tempFileDialog = Application.FileDialog(msoFileDialogFilePicker)
'Allow the user to select multiple workbooks
tempFileDialog.AllowMultiSelect = True
numberOfFilesChosen = tempFileDialog.Show
'Loop through all selected workbooks
For i = 1 To tempFileDialog.SelectedItems.Count
'Open each workbook
Workbooks.Open tempFileDialog.SelectedItems(i)
Set sourceWorkbook = ActiveWorkbook
'Copy each worksheet to the end of the main workbook
For Each tempWorkSheet In sourceWorkbook.Worksheets
tempWorkSheet.Copy after:=mainWorkbook.Sheets(mainWorkbook.Worksheets.Count)
Next tempWorkSheet
'Close the source workbook
sourceWorkbook.Close
Next i
End Sub