Hyperlink covers several cells, how to make it linkable from any of

xenios

Board Regular
Joined
Sep 4, 2020
Messages
91
Office Version
  1. 2016
Platform
  1. Windows
Hello.
I have a link in cell A5, but it covers another 3-4 rows.
How to merge the columns, so it would work clicking only part of the expression?

Below are initial

Initial vba for the link creation if it helps. I have 3 of them of different type. and in attachment how it looks at the moment.
Here is the 1st one.
Sub Hyper()
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "HOTELS" Then
ws.Hyperlinks.Add _
Anchor:=ws.Range("B5"), _
Address:="", _
SubAddress:="HOTELS!A1", _
TextToDisplay:="Back To The Hotel List"
End If
Next ws
MsgBox ("Completed")
End Sub
 

Attachments

  • merge link.png
    merge link.png
    3.4 KB · Views: 6

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Tried to use the following code, Bit it works only on the sheet I'm on, but not for the whole workbook.

Sub merge()
Dim WS As Worksheet

For Each WS In ActiveWorkbook.Worksheets
Range("A5:D5").merge

Next WS
MsgBox ("Completed")
End Sub
 
Upvote 0
Needs to be
Rich (BB code):
WS.Range("A5:D5").merge
 
Upvote 0
Needs to be
Rich (BB code):
WS.Range("A5:D5").merge
Cool, thank you!!

Is there a way to tell it to merge only, when the text in A5 is "Back to The Hotel List", as I'm adding more pages that are different?
And if it's possible for it to merge cells with the same text (To The Top) when I know specific column, but the row varies?
 
Upvote 0
There is but I am loathe to code it for you as merged cells are likely to cause you issues in the future.
Have you looked at using Center across Selection?

 
Upvote 0
There is but I am loathe to code it for you as merged cells are likely to cause you issues in the future.
Have you looked at using Center across Selection?


Thank you for the tip, very useful.
But unfortunately still as a link it works only when you click on the 1st cell :(
 
Upvote 0
I can't believe that I have got myself involved in a post about merged cells :oops: but here goes...

Your first part is easy, it is just
VBA Code:
Sub merge()
    Dim WS As Worksheet

    For Each WS In ActiveWorkbook.Worksheets
        If WS.Range("A5").Value = "Back to The Hotel List" Then WS.Range("A5:D5").merge
    Next WS
    MsgBox ("Completed")
End Sub

As for the 2nd part can you describe in more detail what you want...

Are you just looking down the column, finding one instance of "To The Top" and merging to column D of that row?
Are you doing the same as the above but with multiple instances of "To The Top"?
Or something else?
 
Upvote 0
Sorry for involving you in this :rolleyes:

Here is the link how it looks, it's the same as above, but I don't have specific row, there is the problem.


"Back to The Hotel List" is always in column A.
"To the top" is always in column U
 
Upvote 0
I can't believe that I have got myself involved in a post about merged cells :oops: but here goes...

Your first part is easy, it is just
VBA Code:
Sub merge()
    Dim WS As Worksheet

    For Each WS In ActiveWorkbook.Worksheets
        If WS.Range("A5").Value = "Back to The Hotel List" Then WS.Range("A5:D5").merge
    Next WS
    MsgBox ("Completed")
End Sub

As for the 2nd part can you describe in more detail what you want...

Are you just looking down the column, finding one instance of "To The Top" and merging to column D of that row?
Are you doing the same as the above but with multiple instances of "To The Top"?
Or something else?
Somehow, it's not working, no errors, but things stay the same :(
 
Upvote 0
Sorry for involving you in this :rolleyes:
Not your fault, it's mine. We choose what we get involved in ?

Somehow, it's not working, no errors, but things stay the same :(
Then you just have an hyperlink.
Turn on the macro recorder and carry out the actions in the section "Find All Hyperlinks Linked to Specific Text in Excel" in the link below

Then at the bottom of the code add the lines

VBA Code:
    Dim Findrange As Range
    Set Findrange = Columns("A:A").Find("Back to The Hotel List", , xlValues, xlWhole, xlByRows, xlNext, False)
    If Not Findrange Is Nothing Then Findrange.Resize(, 4).merge

and test. Remember when you put it in your loop you need to add the WS. to the range.

Then do the same with the other word, changing the word and the column in the code (make sure that your wording in the find is correct as your image just shows "Top" not "To the Top").
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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