VBA Cell Reference + hyperlink

JustinLock

New Member
Joined
Sep 22, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I need to reference data in another cell as part of a hyperlink.
The data is part of a url but would change depending on the users input so I can't just use a standard static address.

For example, something that would take the standard google url and use the word "mail" from another cell or if the user inputs "drive" VBA would place that word at the end of the url and run it as a standard hyperlink
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about this one?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range

' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Set KeyCells = Range("A1")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then

' Display a message when one of the designated cells has been
        ' changed.
        ' Place your code here.
        ActiveSheet.Hyperlinks.Add Range("A2"), Address:="https://www.google.com/" & KeyCells.Value & "/"

End If
End Sub
 
Upvote 0
Unfortunately not. The cell being referenced is in another sheet and the code doesn't show as a selection option when assigning a macro to a button, which I assume is down to it being a private sub rather than standard.
Here's what I have so far.

VBA Code:
Sub RoutePlanning()
    Sheet7.Unprotect "DHH2fanclub"
    Sheet7.Activate
        Sheet7.Range("AF1").Select
            Selection.Copy
 Dim chromeFileLocation As String
  Dim hyperlink As String
  hyperlink = "https://www.google.com/"
  chromeFileLocation = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
  Shell (chromeFileLocation & "-url " & hyperlink)
    Sheet7.protect "DHH2fanclub"
End Sub

As I hope you can tell, i'm trying to copy the data from cell AF1 in sheet 7 and paste that onto the generic url but don't know the specific commands to paste that value and then successfully open the browser with that completed url. At this moment the shell function fails too.
 
Upvote 0
Sorry for my English. I can't get you 100%. Maybe someone else may help. I can suggest only the code below as I can tell.

hyperlink = "Google" & Sheet7.Range("AF1").Value
 
Upvote 0
Solution
You should mark my post instead of your post, but no problem :) Nice to hear it has worked!
 
Upvote 0
@JustinLock in future please mark the post with the solution, rather than your post saying it worked. I have changed it for you this time.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,955
Members
449,199
Latest member
Riley Johnson

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