I programmatically generate workbooks with differing numbers of named worksheets. From time to time I programmatically add further named worksheets. I then programmatically alphabetically sort the worksheets but require a VBA generated list of the worksheets to be moved to the beginning of the workbook. The sheet is named “SheetIndex”. The sheet currently first sheet, after alphabetically sorting the worksheets, is not necessarily Sheet1, nor any other. How do I move the “SheetIndex” to the front as clearly “ActiveSheet.Move Before: = ActiveWorkbook.Sheets(1)” does not work!!
Please find solution here by clicking on the below link.
Hope it clarifies your requirement. Please do let me know, If you need any further assistance.
Thank you for your prompt response.
However I have been through the suggested link/s and the solution is not there.
The workbook/s created are actually accounting ledgers, each differing from the next. So in one workbook Sheet1 could be named “Motor Expenses” and in another be named “Electricity”, so the position of sheet1 is totally random, as is the position of every other sheet. Ideally, “Activesheet..Move BEFORE:=Sheets(Sheets.Count)” would work if it existed, but it does not!!
on April 6, 2017.
Hi, I have just found the solution: Private Sub MoveSheetIndexToFront() Application.ScreenUpdating = False Dim FirstSheet As String FirstSheet = Sheets(“SheetIndex”).Range(“A2”).FormulaR1C1 Sheets(“SheetIndex”).Move Before:=Sheets(FirstSheet) ActiveWorkbook.Save End Sub The sheet list is programmatically generated then I run a subsequent macro which looks up the first sheet on the list in Range(“A2”) and moves it as set down. I then move the “SheetIndex” cell in the Index to A2, thus achieving an appropriate indexon April 6, 2017.