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..
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