Adding a Hyperlink

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
149
Evening all,

I'm having problems with the following code. It all works except for the line to add the hyperlink. I have a textbox on a userform called textWebsite where I input a website URL. I need to input that URL into K4 on the relevant worksheet, "ws" and display the text "Link to Website".

The rest of the code works fine and does what I need but nothing happens with this line of code.

Any help will be greatly appreciated as always.

Dan

VBA Code:
Private Sub cmdCreate_Click()
    
    Dim ws As Worksheet
    Set ws = Sheets("Debt Template")
    
    ws.Range("A1") = textDebtFor
    ws.Range("I1") = textOriginalDebt
    ws.Range("I2") = textDebtNowWith
    ws.Range("I3") = textCurrentReference
    ws.Range("I4") = textOriginalReference
    ws.Hyperlinks.Add Range("K4"), Address:=textWebsite, TextToDisplay:="Link to Website"
    
    Dim iRow As Long
    Dim ws2 As Worksheet
    Dim z As Control
        
    Set ws2 = Sheets("List of Debts")
    
    ws2.ListObjects("Table15").ShowTotals = False
    
    iRow = ws2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            
    ws2.Cells(iRow, 1).Value = textDebtFor
    ws2.Cells(iRow, 2).Value = textOriginalDebt
    ws2.Cells(iRow, 5).Value = textOriginalReference
    
    Sheets("Debt Template").Copy After:=Sheets("Debts")
    ActiveSheet.Name = ActiveSheet.Range("I1").Value
    
    ws2.Cells(iRow, 3).Value = "='" & textOriginalDebt & "'!I2"
    ws2.Cells(iRow, 4).Value = "='" & textOriginalDebt & "'!I3"
    ws2.Cells(iRow, 6).Value = "='" & textOriginalDebt & "'!I5"
    ws2.Cells(iRow, 7).Value = "='" & textOriginalDebt & "'!L1"
    
    ws2.ListObjects("Table15").ShowTotals = True
    
    Unload Me
    
    Sheets("Debts").Select
        
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
    ws.Hyperlinks.Add ws.Range("K4"), Address:=Me.TextBox1, TextToDisplay:="Link to Website"
 
Solution

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
149
Thanks Fluff, works perfectly. I should have thought of that really, having one of those days.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,688
Messages
5,637,835
Members
416,985
Latest member
mrindira

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
Top