vba Worksheet_FollowHyperlink - 获取超链接所在的单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10966597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Worksheet_FollowHyperlink - get the cell value in which the hyperlink is located
提问by veganWorld
I have a value in a cell and when I double click on it it takes me to the Named Range Account_Number (which resides on another worksheet) and updates the value.
我在单元格中有一个值,当我双击它时,它会将我带到命名范围 Account_Number(位于另一个工作表上)并更新该值。
My problem is I would like to adapt my code below so it will work with the Worksheet_FollowHyperlink(ByVal Target As Hyperlink) event.
我的问题是我想修改下面的代码,以便它可以与 Worksheet_FollowHyperlink(ByVal Target As Hyperlink) 事件一起使用。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If (ActiveCell.Column = 23 And Not ActiveCell.Value = "") Then
[Account_Number] = ActiveCell.Value
Application.GoTo Reference:=[Account_Number]
End If
End Sub
I would like to put a hyperlink for instance in cell J9 which contains the value 4111 and when I click on the hyperlink it would take me to the Named Range in the other worksheet and update the value of the Named Range to 4111.
例如,我想在包含值 4111 的单元格 J9 中放置一个超链接,当我单击超链接时,它会将我带到另一个工作表中的命名范围并将命名范围的值更新为 4111。
I am uncertain how to dynamically assign the value to the Named Range. Can someone please let me know if this is possible and what the code should be?
我不确定如何将值动态分配给命名范围。有人可以让我知道这是否可行以及代码应该是什么?
Thank you
谢谢
回答by panda-34
If you have made a hyperlink to a named cell, the way to copy the value from hyperlink source cell to its target would be:
如果您创建了一个指向命名单元格的超链接,那么将值从超链接源单元格复制到其目标的方法是:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
ActiveCell.Value = Target.Parent.Value
End Sub
You might want to apply this only to hyperlinks to particular named cell, like:
您可能只想将其应用于特定命名单元格的超链接,例如:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.SubAddress = "Account_Number" Then
ActiveCell.Value = Target.Parent.Value
End If
End Sub