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 LoungerMaudibe
AskWoody_MVPNovember 6, 2013 at 10:04 pm #1421621RetiredGeek
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 LoungerRetiredGeek
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 LoungerWSHowardC
AskWoody LoungerWSsdckapr
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
-
Very Quarrelsome Taskbar!
by
CWBillow
14 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
2 hours, 17 minutes ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
3 hours, 36 minutes ago -
Is your battery draining?
by
Susan Bradley
3 hours ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
5 hours, 33 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
6 hours, 9 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
9 hours, 24 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
7 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
2 hours, 38 minutes ago -
National scam day
by
Susan Bradley
5 hours, 34 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
2 hours, 49 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 7 hours ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 14 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
22 hours, 18 minutes ago -
AI is good sometimes
by
Susan Bradley
1 day, 14 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
1 day, 4 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 14 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 13 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
2 days, 17 hours ago -
Excessive security alerts
by
WSSebastian42
1 day, 8 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
3 days, 2 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
6 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 13 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 7 hours ago -
OS news from WWDC 2025
by
Will Fastie
17 hours, 36 minutes ago -
Need help with graphics…
by
WSBatBytes
1 day, 22 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
3 days, 18 hours ago -
Totally remove or disable BitLocker
by
CWBillow
2 days, 17 hours ago -
Windows 10 gets 6 years of ESU?
by
n0ads
2 days, 20 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
4 days, 4 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.