Adding hyperlink with vba

B-Man

Board Regular
Joined
Dec 29, 2012
Messages
185
Office Version
  1. 2019
Platform
  1. Windows
Trying to add a hyperlink with vba but keep getting errors.
theres alot of code but this is the relevant stuff

basically trying to link the current workbook into a summary workbook
I recorded the macro and the address is correct and I replaced the file with ThisWorkbook.Name
im guessing it has something to do with myrow but i cant work out what or how...

"debug.print myrow" doesnt display anything
"debug.print myrow.address" gives me "$A$140" so tried using "wsDest.Hyperlinks.Add Anchor:=.range(myrow.address)"
not sure what else to do..


VBA Code:
    Dim wsSource    As Worksheet
    Dim wsDest      As Worksheet
    Dim col As Variant             'not a col but repurposed formula

    Set wsSource = ThisWorkbook.Worksheets("Form")

'(code to open workbook removed to make this easier to read)

Workbooks("Summary").Activate
    Set wsDest = ActiveWorkbook.Sheets("Summary")


            col = Application.Match(wsSource.Range("C3"), wsDest.Range("A:A"), 0)

            If IsError(col) Then    'No Match
               Set myrow = wsDest.Range("A" & wsDest.Rows.Count).End(xlUp).Offset(1, 0)  ' Find Column A last row + 1 to paste data
             
            Else    'There is a match - ask to overwrite....
                Dim answer As Integer
          
                answer = MsgBox("Overwrite" & wsSource.Range("C3").Value, vbQuestion + vbYesNo + vbDefaultButton2, "Overwrite")
              
                    If answer = vbYes Then
                  
                        Set myrow = wsDest.Range("A" & col)
                        myrow.EntireRow.ClearContents
                 
                    Else
                  
                        Exit Sub
                      
                    End If
                  
            End If
          
          
wsDest.Hyperlinks.Add Anchor:=myrow, Address:="New\" & ThisWorkbook.Name, TextToDisplay:=wsSource.Range("C3").Value

end sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
after much stuffing around I worked out it was this part of the code... I don't know if its actually a function or not but when I removed it it worked fine. I just set the cell value after linking it.
VBA Code:
 TextToDisplay:=wsSource.Range("C3").Value
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,184
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