Hello,
I have a macro that broke down an Excel workbook into multiple saved files based on a sheet range, beginning with a defined sheet name and ending the sheet before another defined sheet name. I recently updated to Excel 2016 and the loop I have to select the sheets in the range is not working properly - it is only resulting in the last sheet being selected. The 'False' boolean after select sheets (which adds sheets to the current selection, instead of replacing) seems to not be followed. The macro was created and worked fine in Excel 2013.
Does anyone know what my issue could be? Here is the code to create one of the workbooks (starting with the Mid-Atlantic-F sheet and selecting all sheets up to the Florida-F sheet):
Private Sub MidAtlantic()
Sheets("Mid-Atlantic-F").Activate
ActiveSheet.Select
Do Until Sheets(ActiveSheet.Index + 1).Name = "Florida-F"
Sheets(ActiveSheet.Index + 1).Select False
Sheets(ActiveSheet.Index + 1).Activate
Loop
ActiveWindow.SelectedSheets.Copy
ActiveWorkbook.SaveAs Filename:="S:\Accounting Items\Monthly Reports\DistPL\Mid-Atlantic-PL.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
End Sub
I have a macro that broke down an Excel workbook into multiple saved files based on a sheet range, beginning with a defined sheet name and ending the sheet before another defined sheet name. I recently updated to Excel 2016 and the loop I have to select the sheets in the range is not working properly - it is only resulting in the last sheet being selected. The 'False' boolean after select sheets (which adds sheets to the current selection, instead of replacing) seems to not be followed. The macro was created and worked fine in Excel 2013.
Does anyone know what my issue could be? Here is the code to create one of the workbooks (starting with the Mid-Atlantic-F sheet and selecting all sheets up to the Florida-F sheet):
Private Sub MidAtlantic()
Sheets("Mid-Atlantic-F").Activate
ActiveSheet.Select
Do Until Sheets(ActiveSheet.Index + 1).Name = "Florida-F"
Sheets(ActiveSheet.Index + 1).Select False
Sheets(ActiveSheet.Index + 1).Activate
Loop
ActiveWindow.SelectedSheets.Copy
ActiveWorkbook.SaveAs Filename:="S:\Accounting Items\Monthly Reports\DistPL\Mid-Atlantic-PL.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
End Sub