VBA Move selected sheet to beginning

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!!

 

Participant Asked on April 6, 2017 in VBA: Macros.
Add Comment
1 Answer(s)

HI,

Please find solution here by clicking on the below link.

Link 1: VBA Move Worksheet Explained with Examples

Link 2: Move Method of Worksheet Object VBA

Hope it clarifies your requirement.  Please do let me know, If you need any further assistance.

 

Regards,

Someswari D

Expert Answered on April 6, 2017.

Hi Someswari,

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!!

Ivor

 

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 index

on April 6, 2017.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.