Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA Macro, copy the first value in row

Tags:

excel

vba

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!

like image 202
chairSitter Avatar asked Dec 09 '25 11:12

chairSitter


1 Answers

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
like image 173
Shai Rado Avatar answered Dec 11 '25 03:12

Shai Rado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!