When I select a particular cell in the 1st column the data from the cells in the 2nd and 3rd column of the same row as the selected cell should get transferred to a two particular cells in another worksheet. How do I do it?
For example consider two worksheets Sheet1
and Sheet2
Sheet1 Image Sheet2 Image
When I select cell A3
as selected in Sheet2
Image, the data in cell B3
should be automatically transferred to the cell E6
in Sheet1
and data in cell C3
in Sheet2
to cell B2
in Sheet1
.
Please remember I might select any cell in column A
in Sheet2
.
Insert below code into data source sheet (Sheet2 on your screenshot) module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' When selection on the worksheet is changed we check
' that only one cell is selected (not multicell range)
' and this cell is in column 1 (column A)
If Target.Column = 1 And Target.Cells.Count = 1 Then
' If one cell in column A selected, we copy the value
' from a cell right to selected (row is the same, column is greater by 1)
' to the left-up cell of solid destination range on the destination sheet
Sheets("Sheet1").Range("B2").Value = Target.Offset(0, 1).Value
' and the same for a cell where row is the same and column is greater by 2
Sheets("Sheet1").Range("E6").Value = Target.Offset(0, 2).Value
End If
End Sub
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments