VBA table of contents date as hyperlink formatting

Jmoz092

Board Regular
Joined
Sep 8, 2017
Messages
182
Hi, Im trying to create a Table Of Contents Page with hyperlinks to tabs in my workbook. The tabs are named as dates throughout the year in MM-DD-YY format. When I run the macro to create the TOC with hyperlinks, the tab names are displayed in M/DD/YY format. This, appears, to be causing the links to not anchor correctly. Is there a way I can alter the code to fix this problem?

Code:
Sub SheetNamesForTOCa()
 
Dim ws As Worksheet
Dim x As Integer




Application.ScreenUpdating = False


x = 2
For Each ws In Worksheets
If ws.Name Like "01-**-**" Then
     Sheets("Table Of Contents").Cells(x, 1) = ws.Name
     x = x + 1
End If
Next ws


Dim C As Range
With Sheets("Table of Contents")
    For Each C In .Range("A2:A32")
        .Hyperlinks.Add Anchor:=C, Address:="", SubAddress:="'" & C.Value & "'!A1"
    Next C
End With


With Sheets("Table Of Contents")
Range("A1").Value = ("January")
End With


Call SheetNamesForTOCb
Call SheetNamesForTOCc
Call SheetNamesForTOCd
Call SheetNamesForTOCe
Call SheetNamesForTOCf
Call SheetNamesForTOCg
Call SheetNamesForTOCh
Call SheetNamesForTOCi
Call SheetNamesForTOCj
Call SheetNamesForTOCk
Call SheetNamesForTOCl


Application.ScreenUpdating = True


End Sub

Also, How can I code it to where it only makes as many hyperlinks as there are tabs for each month?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try using the "Format" function with the hyperlink subAddress.....

With Sheets("Table of Contents")
For Each C In .Range("A2:A32")
.Hyperlinks.Add Anchor:=C, Address:="", SubAddress:="'" & Format(C.Value, "mm-dd-yy") & "'!A1"
Next C
End With
 
Upvote 0
Thank you, that worked. I had the syntax wrong in applying the format function. Much appreciated
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top