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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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 :beerchug:
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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