Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 为“查找”函数找到的单元格创建超链接_Excel_Vba - Fatal编程技术网

Excel 为“查找”函数找到的单元格创建超链接

Excel 为“查找”函数找到的单元格创建超链接,excel,vba,Excel,Vba,我编写了VBA代码来搜索“Sheet1”中的单词。单词列表在“Sheet2”中。结果与“Sheet1”中的单词和单词的所有单元格地址一起发布在“Sheet3”中 例如,单元地址发布为“$B$26”。我想这是一个超级链接到单元格B26的第1页 我使用了下面的代码 Worksheets("Sheet3").Activate 'Record the address of the data, in the current workbook. With ThisWorkbook.Active

我编写了VBA代码来搜索“Sheet1”中的单词。单词列表在“Sheet2”中。结果与“Sheet1”中的单词和单词的所有单元格地址一起发布在“Sheet3”中

例如,单元地址发布为“$B$26”。我想这是一个超级链接到单元格B26的第1页

我使用了下面的代码

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"
我明白了

运行时错误“1004”:应用程序定义的错误或对象定义的错误


在上面一行
GCell
是找到单词的范围。

这里的问题是
.Cells(i,0)

行/列编号以
1
not
0
开始,因此列
0
不存在,因此会出现错误。还要确保
i
>0


我强烈建议不要使用
.Activate
ActiveSheet
,而是按工作表的名称引用它们。你可能会从阅读中受益

这个

Worksheets("Sheet3").Activate
With ThisWorkbook.ActiveSheet.Range("D2")
可以写成

With ThisWorkbook.Worksheets("Sheet3").Range("D2")

“但是我在上面的一行中得到了一个错误”,而不告诉哪个错误这个信息是非常无用的。还请包括相关代码部分(一行不够)。在使用
Find
后,您是否检查了
GCell
中的
内容,没有任何内容
?对此表示抱歉。现在编辑。是的,我在使用FIND后没有检查GCell。是的,它确实有效!谢谢。。正在检查其他所有东西!!谢谢你,佩赫……是的,它确实起作用了!谢谢。。正在检查其他所有东西!!谢谢你,佩!是的,我也取消了“.Activate”的使用。谢谢!!!:)