I wrote VBA code to search for a word in "Sheet1". The list of words are in "Sheet2". The results are published in "Sheet3" along with the word and all the cell addresses of the word found in "Sheet1".
The cell addresses are published as "$B$26" for example. I want this to be a hyperlink to cell B26 of Sheet1.
I used the below code.
Worksheets("Sheet3").Activate
'Record the address of the data, in the current workbook.
With ThisWorkbook.ActiveSheet.Range("D2")
.Value = "Address of variable:"
.Offset(0, -1).Value = "Variable Name"
.Offset(0, -2).Value = "No of usages"
.Offset(i, 0).Value = GCell.Address
.Offset(i, -1).Value = Txt
.Columns.AutoFit
.Offset(i, 1).Columns.AutoFit
If GCell Is Nothing Then Exit Sub
Sheets("Sheet3").Hyperlinks.Add Anchor:=Sheets("Sheet3").Cells(i,0), _
Address:="", _
SubAddress:="'" & Sheets("Sheet1").Name & "'!" & GCell.Address, TextToDisplay:="Click"
I get
Run time error '1004': Application-defined or object-defined error
on the above line. GCell
is the range where the word is found.