How to hyperlink current sheet to last cell with data in it in a specific row on another sheet

Samlise

New Member
Joined
Nov 8, 2013
Messages
27
Hi

Hope you can help.

I currently have a macro that saves and renames a sheet using a unique name from cell data, but I would also like it to automatically add a hyperlink to this current sheet to the last cell that has data in it in column 'E' on a sheet called "Log".

VBA Code:
' Creates a new sheet based on the last number sequentially created after transfer
   
    Sheets("Transfer").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("Data Validation Lists").Range("AC2").Value
    
    With ActiveSheet
        .Name = Sheets("Data Validation Lists").Range("AC2").Value
        pdfName = .Name
        pdfFullPath = pdfPath & "\" & pdfName
' Create PDF
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:=pdfFullPath
    End With


Cheers
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Assuming that there is a value in EVERY row (ie no blank cells) in column E ...
This formula links to the last used cell in column E in sheet Data Validation Lists
=HYPERLINK("#'Data Validation Lists'!E"&COUNTA('Data Validation Lists'!E:E)+1,"Friendly name")

do you need to use VBA ?
 
Upvote 0
Thanks for that Yongle

I thought VBA was the best way because I am creating a new sheet per data entry, and in the 'log' sheet where a list of all entries is there would be a hyperlink in each row to each of the created sheets.
 
Upvote 0
You said this
a hyperlink to this current sheet to the last cell that has data in it in column 'E' on a sheet called "Log"

which I interpreted as
"a hyperlink to this current sheet to the last cell that has data in it in column 'E'
on a sheet called "Log"

But I now think that you want
a hyperlink from a sheet called "Log" (in the last cell that has data in it in column 'E')
to the current sheet

This creates a link TO the active sheet
Code below places the hyperlink formula in the next row in column E in sheet "Log"
VBA Code:
    Dim aLink As Range, linkTo As String
    Set aLink = Sheets("Log").Cells(Sheets("Log").Rows.Count, "E").End(xlUp).Offset(1)
    linkTo = ActiveSheet.Name
    aLink.Value = "=HYPERLINK(""#'" & linkTo & "'!A1" & """,""" & linkTo & """)"

Adapting that to your code ...

Rich (BB code):
    Dim aLink As Range, linkTo As String
    Sheets("Transfer").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("Data Validation Lists").Range("AC2").Value
    
    With ActiveSheet
        Set aLink = Sheets("Log").Cells(Sheets("Log").Rows.Count, "E").End(xlUp).Offset(1)
        linkTo = .Name
        aLink.Value = "=HYPERLINK(""#'" & linkTo & "'!A1" & """,""" & linkTo & """)"
        .Name = Sheets("Data Validation Lists").Range("AC2").Value
        pdfName = .Name
        pdfFullPath = pdfPath & "\" & pdfName
' Create PDF
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:=pdfFullPath
    End With
 
Upvote 0
LATE EDIT- deleted the duplicated renaming of the sheet in your original code

If you prefer not to use =HYPERLINK formula

This creates a link TO the active sheet
Code below places the hyperlink formula in the next row in column E in sheet "Log"
VBA Code:
    Dim aLink As Range, linkTo As String
    Set aLink = Sheets("Log").Cells(Sheets("Log").Rows.Count, "E").End(xlUp).Offset(1)
    linkTo = ActiveSheet.Name
    aLink.Parent.Hyperlinks.Add aLink, Address:="", SubAddress:="'" & ActiveSheet.Name & "'!A1", TextToDisplay:=ActiveSheet.Name

Adapting that to your code ...

Rich (BB code):
    Dim aLink As Range, linkTo As String
    Sheets("Transfer").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("Data Validation Lists").Range("AC2").Value
 
    With ActiveSheet
         .Name = Sheets("Data Validation Lists").Range("AC2").Value
        Set aLink = Sheets("Log").Cells(Sheets("Log").Rows.Count, "E").End(xlUp).Offset(1)
        linkTo = .Name
        aLink.Parent.Hyperlinks.Add aLink, Address:="", SubAddress:="'" & .Name & "'!A1", TextToDisplay:=.Name   
        pdfName = .Name
        pdfFullPath = pdfPath & "\" & pdfName
' Create PDF
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:=pdfFullPath
    End With
 
Last edited:
Upvote 0
EDIT - CORRECTION TO POST#4
- just spotted your code re-names the sheet TWICE
- moved 2nd incidence ABOVE my inserted lines

Rich (BB code):
   Dim aLink As Range, linkTo As String
    Sheets("Transfer").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("Data Validation Lists").Range("AC2").Value
   
    With ActiveSheet
         .Name = Sheets("Data Validation Lists").Range("AC2").Value
        Set aLink = Sheets("Log").Cells(Sheets("Log").Rows.Count, "E").End(xlUp).Offset(1)
        linkTo = .Name
        aLink.Value = "=HYPERLINK(""#'" & linkTo & "'!A1" & """,""" & linkTo & """)"
        .Name = Sheets("Data Validation Lists").Range("AC2").Value
        pdfName = .Name
        pdfFullPath = pdfPath & "\" & pdfName
' Create PDF
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:=pdfFullPath
    End With
 
Upvote 0
I know I might be pushing it now but how can I make the cells hyperlink text bigger (16) using that VBA?
 
Upvote 0
does this do what you want
VBA Code:
    aLink.Font.Size = 16

To learn how to do this yourself, try using the macro recoder
- amend cell font size, make font bold, italic etc
- look at what has been recoded and adapt it.
 
Upvote 0
Thanks again, I really appreciate your help.

I have been doing most of my VBA that way along with searching but sometimes I just can't get things to work together properly

What I tried for the size change didn't work and was nothing like as elegant as your code!!!
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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