copy paste double click

es0019

New Member
Joined
Jul 24, 2018
Messages
12
Hello
IF anyone can help me please
My question is how can make it work when double clicking on cell copy the contents of this cell and from another cell and then paste the contents from both at another cells.For examble double click on cell D4 copy the contents of D4 and contents of K4 from the same row and paste them with one click to any other active cell let say clicking on cell v60 to paste D4 and on W60 to paste K4

Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified  9/13/2018  8:43:33 PM  EDT
If Not Intersect(Target, Range("D4")) Is Nothing Then
Cancel = True
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Target.Copy Target.Offset(, 18)
Target.Offset(, 7).Copy Target.Offset(, 19)
End If
End Sub
 
Upvote 0
What's not working?
When you double click on D4. D4 value is copied to V4
And K4 is copied to W4.

I think you need to explain again what you want.

You mentioned D4 Then K4 and then V60
 
Upvote 0
Sorry, I mean double click on D4 copy both contents of D4 and K4 and then paste clicking at any 2 continuous cells for example paste them like D4 to V60 and K4 to W60
If its not possible to do that how i can do it simple with double click at any cell of specific column let say D copy contents of the cell and paste to any other cell on worksheet just click on it
Thanks
 
Upvote 0
If you double click on D4 then D4 is the active cell.

You said:
and then paste clicking at any 2 continuous cells for example paste them like D4 to V60 and K4 to W60

So how do you expect to double click on D4 and then expect to paste on some other active cells?
 
Upvote 0
Try these event codes. Install as described by MAIT but remove that code so that there is only one Worksheet_BeforeDoubleClick code.
Test in a copy of your workbook.

This only works for double-clicking in column D (because I think that is what you want) and when selecting the destination, you only need to select the left hand destination cell. That is if you want to paste to V60:W60 you only need to select V60 (though it wouldn't matter if you select both so long as V60 is the active cell)

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column = 4 Then Union(Target, Target.Offset(, 7)).Copy
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Application.CutCopyMode = xlCopy Then
    ActiveSheet.Paste
    Application.CutCopyMode = False
  End If
End Sub
 
Upvote 0
Peter:
You have a good plan I did not think of.
But for your script to work for me I had to enter the line of code:
Cancel=True
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Cancel = True
  If Target.Column = 4 Then Union(Target, Target.Offset(, 7)).Copy
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Application.CutCopyMode = xlCopy Then
    ActiveSheet.Paste
    Application.CutCopyMode = False
  End If
End Sub
 
Upvote 0
Peter:
You have a good plan I did not think of.
But for your script to work for me I had to enter the line of code:
Cancel=True
Good call, thanks. I have my Excel setting to "Allow editing directly in cells" turned off (I hate it on) & forgot that others may have it on.
However, it would be best if your added line was placed after If Target.Column = 4 ..
line so that users could still use the double-click to edit cells in other columns.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column = 4 Then
    Cancel = True
    Union(Target, Target.Offset(, 7)).Copy
  End If
End Sub
 
Upvote 0
after If Target.Column = 4 ..

Hi Peter_SSs I thought Cancel = True should go immediately before End Sub, so it's executed independent of test condition?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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