Possible to have 2 x BeforeDoubleClick events ?

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I use the following code shown below.

Currently when i double click a cell in column A my userform opens.
What i would like to also be able to do is to double click a cell in column B & copy & paste cell values to another worksheet within the same workbook.

Example.
Double click cell B100
"Code will now copy cell values & paste to another worksheet in same workbook"
Worksheet DATABASE copy cell value R100 & paste to worksheet INVOICE cell G14
Worksheet DATABASE copy cell value S100 & paste to worksheet INVOICE cell G15
Worksheet DATABASE copy cell value T100 & paste to worksheet INVOICE cell G16

The cell that is double clicked will always be column B
The cell values to be copied will always be from columns R,S & T on the same row.
The paste locations will always be cells G14,G15 & G16

Thanks


Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub

Cancel = True

Database.LoadData Me, Target.Row

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this instead:

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

   If Not Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then
  
      Cancel = True
  
      DATABASE.LoadData Me, Target.Row
     
   ElseIf Not Intersect(Range("B6", Cells(Rows.Count, "B").End(xlUp)), Target) Is Nothing Then
  
      Worksheets("INVOICE").Range("G14:G16").Value = Application.Transpose(Worksheets("DATABASE").Cells(Target.Row, "R").Resize(, 3).Value)
  
   End If

End Sub
 
Upvote 0
Solution
Hi,
With that code i see a RTE 450, Wrong number of arguements or invalid property asignment.
Then this is shown in yellow.

Rich (BB code):
Worksheets("INVOICE").Range("G14:G16").Value = Application.Transpose(Worksheets("DATABASE").Cells(Target, Row, "R").Resize(, 3).Value)
 
Upvote 0
Sorry - there was a typo. I have corrected it above.
 
Upvote 0
Ah perfect thanks,got there in the end.
Just a thought, should i wish to also copy / past the following of which are from different cells how would i add that into the code.
It would be from the same row but cells arent next to each other.

So
Copy cell vale DATABASE column D to INVOICE L14
Copy cell vale DATABASE column L to INVOICE L16
 
Upvote 0
Add this:

VBA Code:
Worksheets("INVOICE").Range("L14").Value =Worksheets("DATABASE").Cells(Target.Row, "D").Value
Worksheets("INVOICE").Range("L16").Value =Worksheets("DATABASE").Cells(Target.Row, "L").Value
 
Upvote 0
Can the code in Post #2 have pastespecial added to it so where it is pasted on the other worksheet the formula in the cell isnt erased ?
If so please advise how i can do this
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,402
Members
449,156
Latest member
LSchleppi

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