Auto create hyperlink based on 2 cell values

verynewtovba

New Member
Joined
Oct 7, 2016
Messages
5
Hello,


I was wondering if someone could help.


I have a macro which I use as a change record as follows:


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If ActiveSheet.Name = "ChangeRecord" Then Exit Sub

Application.EnableEvents = False

UserName = Environ("USERNAME")

NewVal = Target.Value

Application.Undo

oldVal = Target.Value

lr = Sheets("ChangeRecord").Range("A" & Rows.Count).End(xlUp).Row + 1

Sheets("ChangeRecord").Range("A" & lr) = Now
Sheets("ChangeRecord").Range("B" & lr) = ActiveSheet.Name
Sheets("ChangeRecord").Range("C" & lr) = Target.Address
Sheets("ChangeRecord").Range("D" & lr) = oldVal
Sheets("ChangeRecord").Range("E" & lr) = NewVal
Sheets("ChangeRecord").Range("F" & lr) = UserName

Target = NewVal

Application.EnableEvents = True
End Sub


So, the changes are recorded in a separate sheet called ChangeRecord, and this is working just fine.


What I would like to do is also add a hyperlink in column G which takes me straight to the change record, so, if the cell value in column B is another worksheet named Scotland, and the cell value in column C that was changed is $A$21, then the hyperlink that is auto created in column G takes me to that cell on that worksheet.

The trouble I'm having is that the sheets in Column B could be any other sheet in the same workbook and the cell values in column C could be any cell value on the other sheets as recorded by the ChangeRecord macro, I hope this makes sense.


Any help would be greatly appreciated.
Best regards
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Target.Parent.Name ' this should give you the sheet name
Target.Address ' this should give you the changed cell(s) address

Hyperlinks formulas to places in the document are a bit awkward though.
the format is something like:
Code:
=HYPERLINK("#'[COLOR=#ff0000][B]SheetNameHere[/B][/COLOR]'!"&CELL("address",[COLOR=#ff0000][B]CellAddressHere[/B][/COLOR]),"[COLOR=#ff0000][B]text To Display here[/B][/COLOR]")

or you can add a permanent Hyperlink:
Code:
Sheets("ChangeRecord").Range("F" & lr).Hyperlinks.Add Anchor:=Sheets("ChangeRecord").Range("F" & lr), Address:="", SubAddress:= _
        "'" & Target.Parent.Name & "'!" & target.Address, ScreenTip:="[COLOR=#ff0000]screen tip[/COLOR] [COLOR=#ff0000]if you like [/COLOR]", TextToDisplay:= _
        "[COLOR=#ff0000]The Text to be Displayed in cell[/COLOR]"
 
Upvote 0
Hi,
Many thanks, this works a treat, I modified it slightly for aesthetic purposes;

Sheets("ChangeRecord").Hyperlinks.Add _
Anchor:=Sheets("ChangeRecord").Range("G" & lr), _
Address:="", SubAddress:="" & Sh.Name & " - " & Target.Address, ScreenTip:=" Link to changed cell/cell range "

Best regards
 
Upvote 0
Thanks for the feedback (not getting much these days :confused: ).
Glad I could help.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,816
Members
449,469
Latest member
Kingwi11y

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