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.
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