Copying gets cancelled in VBA

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
2,016
I want to be able to double click a cell and have VBA to copy the row of information.

I currently have:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)'code to copy the row of information to the clipboard


    Application.EnableEvents = False
    Dim s As String
    If Target.Value <> "" Then
        s = "B" & Target.Row & ":H" & Target.Row
        Range(s).Copy
    End If
    Application.EnableEvents = True
        
End Sub

If I step through the code, it works fine, but if I do this normally, I can see it copies but then the cursor goes within the cell and the copy seems to be 'cancelled' ie. you can no longer paste.

In essence I want to double click the cell to copy the row then in a different woorkbook, paste the copied cells.

Must be something basic I'm doing wrong. Any clues?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
you are entirely right, it is something basic ;)

The normal action for double-click is to enter the cell. You are using the "before double-click" event to copy the range, before entering the cell

To prevent it you need to make use of that pre-defined variable you can see in your code header. Add
Code:
Cancel = True
as your first line of code to cancel the default action
 
Upvote 0
this is my 1261st post, and you're the first person ever that's noticed that I am indeed pretty effing heroic

well done (y)
 
Upvote 0

Forum statistics

Threads
1,215,183
Messages
6,123,522
Members
449,103
Latest member
Michele317

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