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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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