Nathalii.
Nathalii.

Reputation: 126

Target.Range.Offset - or something like that

I'm trying to accomplish that if you click on a hyperlink (in column P), it would copy the cell in the same row but in column B to another cell (A3).

I'vre tried with the Target.Range. Offset and other ways. But I can't seem to figure it out.

But I just can't get it right. Here's the code, any ideas?

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    If Target.Range.Address = "$A$4" Then
       MsgBox "This shouldn't happen... Try again"
    Else
        Dim TargetCell As Range
        Set TargetCell = Target.Range
        TargetCell.Offset(-13, 0).Copy
        Range("Vraagnummer").PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
        
        Exit Sub
    End If

End Sub

Upvotes: 0

Views: 1129

Answers (1)

Rory
Rory

Reputation: 34075

You can use this:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    If Target.Range.Address = "$A$4" Then
       MsgBox "This shouldn't happen... Try again"
    Else
        Range("Vraagnummer").Value2 = Cells(Target.Range.Row, "B").Value2
    End If

End Sub

Upvotes: 2

Related Questions