Last updated: April 24, 2010 6:22 PM
Search Contextures Sites ![]()
Sheet Navigator - List and Sort Excel Sheets - Excel 2007
Set up the Workbook
Add the Code to List and Sort Sheets
Modify the XML to Add the Buttons
Save the File as an Add-In
Install and Use the Add-In
Click here for instructions for Excel 2003
version of Excel Sheet Navigator.
Thanks to Dave Peterson, who wrote this technique, and to Ron de Bruin, who adapted the code for Excel 2007. If a workbook contains many sheets, it can be difficult to select the sheet that you want to use. This technique creates a Sheet Navigator Ribbon command, that you can use in any workbook, to create a list of sheets in that workbook. The Sheet Navigator also includes a command that sorts the sheets in alphanumeric order, a command to select a hidden sheet, and to hide the active sheet.
Select a sheet from the dropdown list, to go to that sheet.
Download the zipped sample Excel Sheet Navigator file.
Insert another module, and store the following code on Module2.
'Original code for < Excel 2007 from Dave Peterson 'http://www.contextures.com/xlToolbar01.html Sub DP_RDB_SortSheets(control As IRibbonControl) Dim CalcMode As Long Dim myArr() As String Dim sCtr As Long Dim iCtr As Long On Error Resume Next ActiveSheet.Select If Err.Number > 0 Then MsgBox "There is no workbook open" Err.Clear On Error GoTo 0 Else If ActiveWorkbook.ProtectStructure = True Then MsgBox "Please unprotect this workbook's structure and try again" Exit Sub End If Application.ScreenUpdating = False CalcMode = Application.Calculation Application.Calculation = xlCalculationManual ActiveSheet.DisplayPageBreaks = False ReDim myArr(1 To Sheets.Count) sCtr = 0 For iCtr = 1 To Sheets.Count If Sheets(iCtr).Visible = xlSheetVisible Then sCtr = sCtr + 1 myArr(sCtr) = LCase(CStr(Sheets(iCtr).Name)) End If Next iCtr ReDim Preserve myArr(1 To sCtr) ShellSort myArr For iCtr = 1 To sCtr Sheets(CStr(myArr(iCtr))).Move _ after:=Sheets(Sheets.Count) Next iCtr With Application .Calculation = CalcMode .ScreenUpdating = True End With End If End Sub Sub ShellSort(List As Variant, Optional ByVal LowIndex As Variant, Optional HiIndex As Variant) 'Translation of Shell's Sort as described in ' "Numerical Recipes in C", 2nd edition, Press et al. 'For large arrays, consider Quicksort. This algorithm is at least 'as good up to about 100 or so elements. But with 500 randomized 'elements it is about 27% slower than QSort, and looks 'increasingly worse as the array size increases. 'Dec 17, '98 - David J. Braden Dim I As Long, j As Long, inc As Long Dim var As Variant If IsMissing(LowIndex) Then LowIndex = LBound(List) If IsMissing(HiIndex) Then HiIndex = UBound(List) inc = 1 Do While inc <= HiIndex - LowIndex: inc = 3 * inc + 1: Loop Do inc = inc \ 3 For I = LowIndex + inc To HiIndex var = List(I) j = I Do While List(j - inc) > var List(j) = List(j - inc) j = j - inc If j <= inc Then Exit Do Loop List(j) = var Next Loop While inc > 1 End Sub
Modify the XML to Add the ButtonsFor instructions on adding the buttons to the Ribbon, see Ron de Bruin's web site, and add the following XML:
![]()
Install and Use the Add-InNext, install the Add-In, so you can use it in any workbook.
- Open Excel.
- On the Excel Ribbon, click the Microsoft Office button, then click Excel Options.
- In the Category list, click on Add-Ins.
- From the Manage drop down, select Excel Add-ins, then click Go
- Find your Add-In in the list, and add a check mark to its name.
- Click OK to close the Add-Ins dialog box.
Now you can use the add-in in any workbook.
- The Sheet Navigator commands should appear at the far right of the Home tab on the Ribbon.
- Click the Select a Sheet command, to view a list of sheets in the active workbook.
- From the dropdown list, select a sheet, and that sheet will be activated.
You can add the Sheet Navigator commands to the Quick Access Toolbar (QAT):
- Right-click on the Select a Sheet command in the Ribbon.
- Click on Add to Quick Access Toolbar.
Note: If you're new to macros, you may want to read David McRitchie's intro at: http://www.mvps.org/dmcritchie/excel/getstarted.htm
Contextures Inc., Copyright ©2012
All rights reserved.