Please, try the next solution. It uses the hyperlink only to call a function able to extract the sheet and the range from the hyperlink TextToDisplay:
- Copy the next
Sub in a standard module (to create a hyperlink). The hyperlink can be manually created, too:
Sub testCreateHyperlink()
ActiveSheet.Hyperlinks.Add Anchor:=Range("a20"), Address:="", _
ScreenTip:="Select discontinue range in anohter sheet", _
TextToDisplay:="Documentation|A4,A7,A8,A15,B20"
End Sub
Many such hyperlinks can be created. The actual rule runs a macro for hyperlinks in columns 1, but the code can easily be adapted according to your need.
- In the sheet module, where the hyperlink(s) exist, copy the next event code:
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Column = 1 Then
Dim sh As Worksheet
Set sh = Worksheets(Split(Target.Range.Value, "|")(0)): sh.Activate
sh.Range(Split(Target.Range.Value, "|")(1)).Select
End If
End Sub
- Click the above created hyperlink(s) and selection will be done in the combination 'sheet name|range' kept by clicked cell
TextToDisplay hyperlink.
In this way, the string keeping the range address can be much longer (not needing the sheet name for each continuous range, plus concatenation characters). If the limitation of 256 characters is reached, I have in mind a solution to solve such an issue, too...
- In order to rapidly/easily fill the
TextToDisplay at hyperlink creation, some functions can be imagined. The next one creates the necessary string from selected cells:
Private Function strSelTextToD() As String
Dim sh As Worksheet: Set sh = ActiveSheet
strSelTextToD = sh.Name & "|" & Selection.Address(0, 0)
End Function
And following one, create it from cells having interior green colored (65280):
Private Function strTextToD() As String
Dim sh As Worksheet, Cel As Range, rng As Range
Set sh = ActiveSheet
For Each Cel In sh.UsedRange.cells
If Cel.Interior.Color = vbGreen Then
If rng Is Nothing Then
Set rng = Cel
Else
Set rng = Union(rng, Cel)
End If
End If
Next
If Not rng Is Nothing Then strTextToD = sh.Name & "|" & rng.Address(0, 0)
End Function
The above two functions can be called in the next way:
Sub testStrHypTTD()
Dim strToDisp As String
strToDisp = strSelTextToD: Debug.Print strToDisp
strToDisp = strTextToD: Debug.Print strToDisp
End Sub
And the returned string can be simple used, in the Sub creating the hyperlink, like this:
'...
TextToDisplay:=strSelTextToD