Since your variation gives no error, but not the result I'm looking for, I've tried to lay this out more completely below and shown my current version of the code (that throws subscript out of range errors).
Essentially I have 2 sheets in the same workbook. The first is laid out like a form, allowing the user to review data in a nice format. The second is like a database, where every row corresponds to a unique record. I need to write a "save" macro from the form-type sheet that can handle either of 2 circumstances.
1) the macro is saving a new record to a row of the target "database type" sheet
2) the macro could be saving a data updated record to a same row of the target sheet that it was retrieved from in the first place.
Ok, so I'm working on the part of the save macro that will copy a hyperlink (and preferably only the hyperlink, not colors/formats) and paste it into the database sheet.
I have tried what seems like dozens of variations all either ending in a subscript error (when I use the .hyperlinks(1).address method) or not generating an error, but also not copying the hyperlink (just the text value of the cell).
The hyperlink to be copied is in sheet TE_Form , in a named range "TE_Image" which is in cell C27
The destination will either be sheet LogDB cell BX6 (when this is a new record being added to LogDB) -or- sheet LogDB cell BX? (where the ? is the row number of an existing record in the DB_Log).
In the case when it is an existing record being copied to LogDB, I use the .Find method and a variable rw to identify which row within column BX that link should be pasted.
Here is what I've got now (boiled down from a long macro):
Sub link_copy_test()
Dim RecID As Integer
Dim screenTip As String
Dim textToDisplay As String
Dim FindRow As Variant
Dim rw As Long
screenTip = "Link to Chart Image"
textToDisplay = "Chart Image"
RecID = Worksheets("TE_Form").Range("A1").Value
With Worksheets("LogDB")
Set FindRow = Worksheets("LogDB").Range("C:C").Find(What:=RecID, LookIn:=xlValues)
If Not FindRow Is Nothing Then
rw = FindRow.Row
End If
End With
If IsEmpty(Range("A1").Value) = True Then
Range("TE_Image").Hyperlinks.Add Anchor:=Range("TE_Image"), Address:=Range("BX6").Hyperlinks(1).Address, screenTip:=screenTip, textToDisplay:=textToDisplay
Else
Range("TE_Image").Hyperlinks.Add Anchor:=Range("TE_Image"), Address:=Range("BX" & rw).Hyperlinks(1).Address, screenTip:=screenTip, textToDisplay:=textToDisplay
End If
End Sub
And before I forget, I really appreciate the help.
Bookmarks