VBA & Macro Problems

Create an Excel VBA Sheet Index with B2 Hyperlinks and B3 Values

Rana GarciaRana Garcia Nov 22, 2026 869 views

Question details

Create an Excel worksheet index that uses each sheet's B2 value as hyperlink text and shows its B3 value in the next column.

Create an Excel VBA Sheet Index with B2 Hyperlinks and B3 Values
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
The user wants a macro to list worksheets on an INDEX sheet, with links in column C and associated values in column D.
Observed behavior
The desired index displays each source sheet's B2 value as a clickable link and its B3 value beside it.
Before you start

In desktop Excel, create or identify a worksheet named INDEX and check that columns C and D are available from row 4 onward. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the code.

Solution 1Recommended

Build the worksheet index with an Excel VBA macro

Use this complete macro to create links to each worksheet and place its B3 value beside the link.

The macro uses the B2 value for the link text and links to cell A1 on the source sheet. If B2 is blank or contains an error, it uses the worksheet name instead.

The macro skips the INDEX sheet and overwrites existing entries in columns C and D starting at row 4. It does not remove leftover rows from an earlier, longer index.

1
Open the VBA editor

In the workbook containing the INDEX sheet, open Developer > Visual Basic, or press Alt+F11 on Windows.

2
Insert the macro

In the VBA editor, select the workbook project, choose Insert > Module, and paste the following code: Sub BuildSheetIndex() Dim ws As Worksheet Dim idx As Worksheet Dim nRow As Long Dim linkText As String Dim target As String Set idx = ThisWorkbook.Worksheets("INDEX") nRow = 4 For Each ws In ThisWorkbook.Worksheets If ws.Name <> idx.Name Then linkText = ws.Name If Not IsError(ws.Range("B2").Value) Then If Len(CStr(ws.Range("B2").Value)) > 0 Then linkText = CStr(ws.Range("B2").Value) End If End If target = "'" & Replace(ws.Name, "'", "''") & "'!A1" With idx.Range("C" & nRow) If .Hyperlinks.Count > 0 Then .Hyperlinks.Delete idx.Hyperlinks.Add Anchor:=idx.Range("C" & nRow), Address:="", SubAddress:=target, TextToDisplay:=linkText .HorizontalAlignment = xlLeft End With idx.Range("D" & nRow).Value = ws.Range("B3").Value nRow = nRow + 1 End If Next ws End Sub

3
Run and check the index

Return to Excel, choose Developer > Macros, select BuildSheetIndex, and click Run. On INDEX, click a link in column C and check that column D contains the corresponding sheet's B3 value.

4
Remove any old entries

If a previous index had more sheets, select the leftover cells below the new entries in columns C and D and clear them.

Build the worksheet index with an Excel VBA macro
Keep the macro in the indexed workbook: The code uses ThisWorkbook, so it indexes the workbook that contains the macro. The worksheet name must be INDEX.
Free Microsoft Office alternative

Manage spreadsheet indexes with WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. It supports a smooth move between common Office formats, although it does not fix an Excel VBA error and macro compatibility can vary.

Organize worksheet links and index values in a familiar spreadsheet interfaceOpen and edit Microsoft Excel formats such as XLSXUse a free, lightweight office suiteWork with familiar menus when moving from Microsoft Office
microsoft office alternative - wps office

Frequently Asked Questions

What happens if a worksheet's B2 cell is empty?

The sample macro uses the worksheet name as the hyperlink text when B2 is empty or contains an error.

Can I link to a cell other than A1?

Yes. In the macro, change the !A1 portion of the target assignment to the cell you want, such as !B2.

Why does the macro say the INDEX sheet cannot be found?

Check the sheet tab in the workbook containing the macro and rename it INDEX, or change Worksheets("INDEX") in the code to match the existing sheet name.

Will the index update automatically when B2 or B3 changes?

No. Run BuildSheetIndex again from Developer > Macros to refresh the links and values, then clear any leftover rows if the number of sheets has decreased.