Adding a Hyperlink

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
161
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
VBA Code:
    ws.Hyperlinks.Add ws.Range("K4"), Address:=Me.TextBox1, TextToDisplay:="Link to Website"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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