VBA Help Need - Creating a Table of Contents Sheet with Hyperlinks

bbalch

Board Regular
Joined
Feb 23, 2015
Messages
53
Hello everyone. I'm trying to create a macro that will insert a new tab called "SheetList" at the beginning of my workbook. This tab has "Table of Contents" in cell A4. I would like for the sheet names to be listed starting in cell B5 and continuing down until all sheets are listed. Beside the sheets names in B5 down I'm trying to create a hyperlink formula that links to corresponding tab. The code below inserts the sheet names and hyperlinks, however it starts the sheet list in B1. Any suggestions on how to modify so that the sheet names start in B5 instead of B1?

I'm not sure if it matters but I'm using Excel 2016 on Office 365.

Thanks in advance for your help and suggestions.


Code:
Sub SheetList()' Add SheetList at beginning of workbook


    Sheets.Add Before:=Sheets(1)
    Sheets(ActiveSheet.Name).Name = "SheetList"
    
'Add title and formatting


    Range("A4").Select
    Selection.FormulaR1C1 = "Table of Contents"
    Cells.Select
    With Selection.Font
        .Name = "Segoe UI Light"
        .FontStyle = "Regular"
      
    End With
    Range("A3").Select
    With Selection.Font
        .Name = "Segoe UI Light"
        .FontStyle = "Bold"
        .Size = 20


    End With
    
    
  ' Add Sheet Names in workbook
    
    Dim x As Integer
    For x = 1 To Worksheets.Count
    Cells(x, 2).Value = Worksheets(x).Name
    Next x
    
' Add hypyerlinks to tabs
    
     Dim LastRowColumnB As Long
       LastRowColumnB = Cells(Rows.Count, 2).End(xlUp).Row
        Range("C1:C" & LastRowColumnB).Formula = "=HYPERLINK(""#'""&RC[-1]&""'!A1"",RC[-1])"
    
    
End Sub
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,272
Try this:
Code:
Sub SheetList() ' Add SheetList at beginning of workbook
'Modified 4-24-18 7:35 PM EDT
    Sheets.Add Before:=Sheets(1)
    Sheets(ActiveSheet.Name).Name = "SheetList"
    
'Add title and formatting

    Range("A4").Select
    Selection.FormulaR1C1 = "Table of Contents"
    Cells.Select
    With Selection.Font
        .Name = "Segoe UI Light"
        .FontStyle = "Regular"
      
    End With
    Range("A3").Select
    With Selection.Font
        .Name = "Segoe UI Light"
        .FontStyle = "Bold"
        .Size = 20

    End With
    
    
  ' Add Sheet Names in workbook
    
    Dim x As Integer
    For x = 1 To Worksheets.Count
    Cells(x + 4, 2).Value = Worksheets(x).Name 'Modified this line
    Next x
    
' Add hypyerlinks to tabs
    
     Dim LastRowColumnB As Long
       LastRowColumnB = Cells(Rows.Count, 2).End(xlUp).Row
        Range("C5:C" & LastRowColumnB).Formula = "=HYPERLINK(""#'""&RC[-1]&""'!A1"",RC[-1])" 'Modified this line
    
    
End Sub
 

Forum statistics

Threads
1,081,546
Messages
5,359,455
Members
400,529
Latest member
Ratish52

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top