PDA

View Full Version : on click a cell and copy to another cell



sswong98
11-14-2007, 06:05 PM
Hey Guys,

I am very very new to VBA. I am trying to figure out way where a user clicks on a cell, the information in that cell is copied and pasted to another cell in the same worksheet. Thanks for any help.

Reafidy
11-14-2007, 07:10 PM
Try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
Target.Copy Range("B1")
End If
End Sub

If the user clicks on any cell within A1:A10 the cell will be copied to B1

Charlize
11-15-2007, 04:18 AM
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.Copy Application.InputBox("Give destination cell ...", _
"Place copied cell where ?", Type:=8)
Cancel = True
End Sub

sswong98
11-15-2007, 10:02 AM
Hello Reafidy, Thanks for the code, it work great. There is one other thing I forgot to mention... Say the range is B1:B10, but I want to copy the data from cell A1:A10 to cell C1. So for example, the user click on B1, the data from A1 is copied over to C1.

Reafidy
11-15-2007, 12:58 PM
Try:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B1:B10")) Is Nothing Then
Target.Offset(, -1).Copy Target(, 2)
End If
End Sub