Consulting

Results 1 to 5 of 5

Thread: on click a cell and copy to another cell

  1. #1
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location

    on click a cell and copy to another cell

    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.

  2. #2
    VBAX Regular
    Joined
    May 2007
    Posts
    18
    Location
    Try:

    [vba]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[/vba]

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

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    [VBA]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[/VBA]

  4. #4
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location
    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.

  5. #5
    VBAX Regular
    Joined
    May 2007
    Posts
    18
    Location
    Try:

    [VBA]
    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
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •