• Ask a Question
150
Insert Image Size must be less than < 5MB.
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel
      Participant

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

       

      Asked by AbsoluteIvor on April 6, 2017 in VBA: Macros.
      1 Answers
      Expert

      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

      Answered by Valli 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.
      Cancel
      Add comment