Hyperlinking a cell to another cell in the same worksheet

不羁岁月 提交于 2019-12-25 01:37:24

问题


Hi All,

I am reposting the post from today afternoon since no one gave an answer. I'd like to write an Excel VBA code such that if x is clicked under column A, the green rectangle moves to the 1 to the farthest right: Clicking first x at A1 arrives at (1, P3), A2 -> (2, P2), A3 -> (3, P2), A4 -> (4, P3).

Below, so far I've written the code with an intention to hyperlink A1, A2, A3, and A4 to corresponding PCell. I am not sure how to fetch the 1's on the farthest right under the P columns. Can any of you give an answer or suggestion? If there is another way to do it, I am willing to listen. Thank you.

Sub GoToPCell()

Dim i As Integer, PCell As String

PCell =


For i = 1 To 4

ActiveSheet.Hyperlinks.Add Cells(i, 1), Address:="", SubAddress:="'" & Sheet1.Name & "'!PCell"


Next i

End Sub

回答1:


As Mr. BigBen comment the main part to solve your problem. I have just post full sub as below. Try...

Sub GoToPCell()
Dim i As Integer, PCell As String
    For i = 1 To 4
        PCell = Cells(i, Columns.Count).End(xlToLeft).Address
        ActiveSheet.Hyperlinks.Add Cells(i, 1), Address:="", SubAddress:="'" & Sheet1.Name & "'!" & PCell
    Next i
End Sub


来源:https://stackoverflow.com/questions/58869211/hyperlinking-a-cell-to-another-cell-in-the-same-worksheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!