Problem with my DoubleClick event

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Problem with my DoubleClick event

Post by chamdan »

Hi,
I have the following code in the Wortksheet_Doublick, which give an error 1004 when debugging.

Code: Select all

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim isect As Range

    Set isect = Intersect(Target, Range("I:I"))
    Range("A" & Target.Row & ":I" & Target.Row).Select
    Selection.Copy

    Sheets("Sheet1").Select
    Range("A" & Target.Row & ":I" & Target.Row).Select   '<----------- This is where the error is.

    Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub


Am I doing something wrong?


Chuck
Last edited by chamdan on 14 May 2016, 17:13, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Problem with my DoubleClick event

Post by HansV »

In a worksheet module, the line

Range("A" & Target.Row & ":I" & Target.Row).Select

refers to the sheet running the code. But since you selected Sheet1, you cannot select a range on the sheet running the code.

Solution: avoid selecting cells.

Code: Select all

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Range("A" & Target.Row & ":I" & Target.Row).Copy
    Sheets("Sheet1").Range("A" & Target.Row & ":I" & Target.Row).PasteSpecial _
        Paste:=xlPasteAllUsingSourceTheme
    Application.CutCopyMode = False
End Sub
I removed the lines involving iSect since you don't do anything with the range iSect.
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Problem with my DoubleClick event

Post by Rudi »

Try this version without the select method which was giving the unexpected error:

Code: Select all

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim isect As Range
Dim lRow As Long
    Set isect = Intersect(Target, Range("I:I"))
    Range("A" & Target.Row & ":I" & Target.Row).Copy
    Sheets("Sheet1").Range("A" & Target.Row & ":I" & Target.Row).PasteSpecial Paste:=xlPasteAllUsingSourceTheme
    Application.CutCopyMode = False
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Problem with my DoubleClick event

Post by chamdan »

Thanks! It worked.

Cheers!

Chuck