doubleclick Copy/paste cell VBA: Going one further

Zetroza

New Member
Joined
May 5, 2015
Messages
12
Hi,
I have had moderate sucess with my first few attempts at implementing vba code but I am still struggeling a bit here and I cant tell how advanced this problem may become to solve.
In the below table I am trying to create a macro(s) that will:
1. upon doubleclick in cell of column "fruit", copy and paste that cell into "a1" on "sheet2"
and,
2. upon doubleclick in cell of column "colour", copy and paste that cell into "a1" on "sheet3"

Fruit
Coloumn X , Y, Z etcColour
AppleRed
AppleGreen
LemonYellow
LimeGreen
BananaYellow

<tbody>
</tbody>

The following code solves step 1 only, but my attempts to input the 2nd command alongside it are proving extreamly difficult.
Any help would be greatly appreciated.
Many thanks,


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("a2:a6")) Is Nothing Then
Cancel = True
If Target.Row > 1 And Len(Target.Value) Then Worksheets("sheet2").Range("a1").Value = Target.Value
Worksheets("sheet2").Activate
End If
End Sub


Notes:
*The above code directs you to the worksheet also.
*Assume there are other coloumns (x,y,z) between the 2 in question.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try something like this. Change the 2nd column Range to suit.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_BeforeDoubleClick([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range, Cancel [color=darkblue]As[/color] [color=darkblue]Boolean[/color])
    [color=darkblue]If[/color] [color=darkblue]Not[/color] Intersect(Target, Range("a2:a6")) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        Cancel = [color=darkblue]True[/color]
        [color=darkblue]If[/color] Target.Row > 1 And Len(Target.Value) [color=darkblue]Then[/color] Worksheets("sheet2").Range("a1").Value = Target.Value
        Worksheets("sheet2").Activate
    [color=darkblue]ElseIf[/color] [color=darkblue]Not[/color] Intersect(Target, Range("[COLOR=#ff0000]Z2:Z6[/COLOR]")) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        Cancel = [color=darkblue]True[/color]
        [color=darkblue]If[/color] Target.Row > 1 And Len(Target.Value) [color=darkblue]Then[/color] Worksheets("sheet3").Range("a1").Value = Target.Value
        Worksheets("sheet3").Activate
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0
Absolutely perfect,
Incredible response,
Thanks you very much

You're welcome. Thanks for the feedback.

Also, you don't really have to test if Target.Row > 1 as it will always be true if it passed the Intersect test
 
Upvote 0
Hi sir,
i am a beginner
can any one help me to create a marco such a way that....
In a sheet
let b1 to b50 contains some data...
In same sheet
1. I selected cell a1 by clicking it
2. Now i double clicked b1 or b2 or .....b100
3. Then value in b1 or b2 or ....b100 must copy to a1 and cell a2 must selected to ready for next double click event

some please help me
thanking in advance
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top