chairSitter
chairSitter

Reputation: 81

Excel VBA Macro, copy the first value in row

I am trying to write a macro that will copy the value in column A of the same row of the cell I have selected.

So for example, if my spreadsheet looked like:

| John | Doe | 123 | 456 | Apples |

and the selected cell was the one containing 123, it would copy John. If I selected the 456 cell, it would still copy John. Make sense?

I understand the Selection.Offset( ,-3).Copy function (would copy the cell three columns back, same row as current selection) but I'm not starting in the same column every time, so I think I need a more distinct references.

Thanks for the help!

Upvotes: 3

Views: 603

Answers (1)

Shai Rado
Shai Rado

Reputation: 33682

Add the code below in the Worksheet_SelectionChange event of your relevant sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

' copy the cell in Column "A" of the same row clicked
Range("A" & Target.Row).Copy

End Sub

Upvotes: 3

Related Questions