Conditional Hyperlink with drop down list

xzaqus

New Member
Joined
Sep 24, 2017
Messages
33
I have a drop down list with 4 options - A, B, C, and D. I need that only when C is selected from the list, the cell itself has a hyperlink. So, if cell B4 gets the value C from the drop down list, then C or the cell itself should be hyperlinked to say Google.com. If any other value is selected, then no hyperlink.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try placing the following sub in the code section of the sheet where you have your dropdown in cell B4:
Code:
Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$B$4" Then Exit Sub
    If Target.Value = "C" Then
        ActiveSheet.Hyperlinks.Add Target, "http://www.google.com", , , "C"
    Else
        Target.Hyperlinks.Delete
    End If
End Sub
 
Upvote 0
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
If Target.Value = "C" Then
Link = "https://www.Google.com"
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
End If
End If
Exit Sub
M:
MsgBox "Bad Link"
End Sub
 
Upvote 0
Not sure why you would want to do a thing like you asked for in Post #1
But you could go into the data validation list and add values like:

Google,Apple,Cnn,Fox

Then using this script you would be taken to that site when you choose the value from the drop down list.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
Dim ans As String
ans = "https://www."
anss = ".com"
Link = ans & Target.Value & anss
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True
End If
Exit Sub
M:
MsgBox "Bad Link"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
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