Excel VBA Macro, copy first value in row

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

So, for example, if my table looked like this:

| John | Doe | 123 | 456 | Apples |

      

and the selected cell was the one that contains 123, it will copy John. If I had selected cell 456, it would have copied John anyway. It makes sense?

I understand the function Selection.Offset( ,-3).Copy

(would copy a cell three columns back, the same row as the current selection), but I don't start in one column every time, so I think I need clearer references.

Thanks for the help!

+3


source to share


1 answer


Add the following code to the event of Worksheet_SelectionChange

your respective 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

      

+3


source







All Articles