[VBA] Create Hyperlink to latest worksheet in Workbook

PingPongMan

New Member
Joined
Nov 27, 2018
Messages
1
Hey guys,

as part of a larger macro, I want to insert a code that creates a link to the latest sheet of the workbook and name it according to the text in the selcted cell.
This was asked in a simliar way before (https://www.mrexcel.com/forum/excel...ng-hyperlink-last-worksheet-workbook-vba.html), but when I inserted the exact same code, the link saying "hello" was created but clicking on it lead to an error saying the reference is invalid, which is the same error Im getting with the code below:


Code:
Sub CreateHyperlinkToLastSheet()

Range("D43").Select
Dim x As Integer

x = ThisWorkbook.Sheets.Count

    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "x!A1", TextToDisplay:=TextToDisplay:=Range("D43").Value

End Sub


If anybody could help me with that, thank you very much in advance!

Best regards!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Code:
Sub Macro1()
Dim a As String


     a = Sheets(Sheets.Count).Name
     Sheets(a).Range("A1") = Sheets("sheet1").Range("d43").Value
    Sheets(a).Activate
    Sheets(a).Range("A1").Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        a & "!A1", TextToDisplay:=Sheets("sheet1").Range("d43").Value
End Sub
you may modify this to suit your needs
ravi shankar
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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