问题
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