I would like a macro to create an index sheet that updates when new sheets are added or deleted
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Macro to create index sheet
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Macro to create index sheet
- This topic has 16 replies, 5 voices, and was last updated 10 years, 8 months ago.
Viewing 10 reply threadsAuthorReplies-
RetiredGeek
AskWoody_MVPNovember 6, 2013 at 7:50 am #1421464Howard,
Here’s one possible solution:
Code:Option Explicit Private Sub Worksheet_Activate() Dim sht As Worksheet Dim lCurRow As Long lCurRow = 2 For Each sht In ActiveWorkbook.Sheets If sht.Name "Index" Then Cells(lCurRow, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _ sht.Name & "!A1", TextToDisplay:=sht.Name lCurRow = lCurRow + 1 End If Next sht '*** Clear out any deleted sheets *** Cells(lCurRow, 1).Select Range(Selection, Selection.End(xlDown)).Delete Shift:=xlUp End Sub
35367-Excel-index
Note that the code goes in the Index Sheet module. See attached sample file. The index is automatically recreated every time the Index sheet is selected.
35368-VBA-Excel-Create-Index-sheet
HTH :cheers: -
WSHowardC
AskWoody Lounger -
WSldbarua
AskWoody LoungerOctober 15, 2014 at 8:33 am #1471123Howard,
Here’s one possible solution:
Code:Option Explicit Private Sub Worksheet_Activate() Dim sht As Worksheet Dim lCurRow As Long lCurRow = 2 For Each sht In ActiveWorkbook.Sheets If sht.Name "Index" Then Cells(lCurRow, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _ sht.Name & "!A1", TextToDisplay:=sht.Name lCurRow = lCurRow + 1 End If Next sht '*** Clear out any deleted sheets *** Cells(lCurRow, 1).Select Range(Selection, Selection.End(xlDown)).Delete Shift:=xlUp End Sub
35367-Excel-index
Note that the code goes in the Index Sheet module. See attached sample file. The index is automatically recreated every time the Index sheet is selected.
35368-VBA-Excel-Create-Index-sheet
HTH :cheers:Works great, just note that sheet names must not have spaces or dashes. Apparently, these special characters break the code.
-
-
WSHowardC
AskWoody Lounger -
Maudibe
AskWoody_MVPNovember 6, 2013 at 10:04 pm #1421621 -
RetiredGeek
AskWoody_MVPNovember 7, 2013 at 6:41 am #1421663Maud,
Actually the code will work where ever the Index sheet is located as long as it is named Index. Of course the Index sheet will NOT show up in the Index. I has assumed (oh that nasty word :lol:) the idea was to get to the sheets quickly thus the hyperlinks. :cheers:
-
Maudibe
AskWoody_MVPNovember 7, 2013 at 8:54 am #1421688Assuming the Index sheet is the first sheet
RG,
I was referring to the code I posted. It must be in the Worksheet_Activate event subroutine of the first sheet, Worksheet(1), so that the code will display Worksheet(2) and Worksheet(3) as I cycles from 2 to the number of sheets.
Your code is gold as always!
Maud
-
RetiredGeek
AskWoody_MVPNovember 7, 2013 at 10:37 am #1421711RG,
Your code is gold as always!
MaudMaud,
Don’t I WISH!
:cheers:
-
-
WSsdckapr
AskWoody Lounger -
RetiredGeek
AskWoody_MVPNovember 10, 2013 at 6:44 am #1422064Steve,
Thanks for updating this. I never put spaces in sheet names, a habit developed decades ago, so I keep forgetting about this requirement when I write code. I’ll see if I can cram one more thing into this old cranium as it is always good practice to allow for all possibilities. Thanks again! :cheers:
-
WSsdckapr
AskWoody LoungerNovember 10, 2013 at 7:11 am #1422069FYI, without the spaces the single quotes are NOT required but in cases like this it does NOT hurt to add them if not required. using them in INDIRECT , HYPERLINK. etc formulas around the sheet name will not hurt if they are not required (XL will remove them) but are neccessary when required and it is a good habit to just use them even if the names do not require them.
Steve
-
WSsdckapr
AskWoody Lounger -
WSHowardC
AskWoody Lounger -
WSsdckapr
AskWoody Lounger -
WSldbarua
AskWoody Lounger
-
Viewing 10 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
2 hours, 31 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
5 hours, 28 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
33 minutes ago -
National scam day
by
Susan Bradley
1 hour, 17 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
23 hours ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 7 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
15 hours, 26 minutes ago -
AI is good sometimes
by
Susan Bradley
1 day, 7 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
21 hours, 35 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 7 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 6 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
2 days, 10 hours ago -
Excessive security alerts
by
WSSebastian42
1 day, 1 hour ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
2 days, 19 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
13 hours ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 7 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day ago -
OS news from WWDC 2025
by
Will Fastie
10 hours, 44 minutes ago -
Need help with graphics…
by
WSBatBytes
1 day, 15 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
3 days, 11 hours ago -
Totally remove or disable BitLocker
by
CWBillow
2 days, 10 hours ago -
Windows 10 gets 6 years of ESU?
by
n0ads
2 days, 13 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
3 days, 22 hours ago -
Search Forums only bring up my posts?
by
Deo
3 hours ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
4 days, 9 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
13 hours, 57 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
6 hours, 57 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
4 days, 20 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
4 days, 21 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.