Excel 2010: When Cell B1 clicked add contents of adjacent cell (A1, or C1) to another cell
I'm developing an Excel doc开发者_运维百科ument for my own use, but I've hit a wall in getting everything to work as I want it, I don't really know much VBA, but I understand I'll probably require it to get what I want working... :)
What I need is, for example, when cell B1 is clicked, I want Excel to take the contents of an adjacent cell, (it could be A1 or C1), and duplicate / paste / copy it into the next blank cell of a row in another sheet.
I'd preferably like it to be flexible, so that I can simply duplicate it for B2 (and it would then apply for A2 or C2), since it would be required for hundreds of cells - and entering it manually constantly would be a total pain. I don't really want to use forms or check boxes...
Thanks!, Luke.
Maybe I misunderstood your question but I'd go about it like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim WS As Worksheet: Set WS = Worksheets(2)
Dim adjacent As Range: Set adjacent = Target.Offset(0, 1)
WS.Range(adjacent.Address).Value = adjacent.Value
End Sub
精彩评论