what's wrong with this?

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Selection.Cut
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
    With Selection.Paste
    End With
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi:
Code:
    With Selection
        .Paste
    End With

Although I don't understand why you need to paste after having just inserted the selection...or if this is even possible...what are you pasting? There would need to be something on the clipboard, perhaps. Maybe I am just tired... :lol:

Regards.
 
Upvote 0
In A1 I have 1
in A2 I have 2
in A3 I have 3

When I double click A2 the result should become
A1 is 2
A2 is 1
A3 is 3

When I dbl click a cell in the A column the code should create a new row in Row 2 and paste the dbl click selected value
Thx
 
Upvote 0
Jindon thaks
Code s/b:
Code:
Selection.Cut
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
thks to all
 
Upvote 0
If you don't want to have to select the row first:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    'cut and move row where cell is double-clicked
    Target.EntireRow.Cut
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
    
    'disable normal double-click behavior
    Cancel = True

End Sub
 
Upvote 0
try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim temp As Variant
    If Target.Column <> 1 Then Exit Sub
    If Target.Row < 2 Then Exit Sub
    Cancel = True
    temp = Range("a1", Target.Offset(-1)).Value
    Range("a1").Value = Target.Value
    If IsArray(temp) Then
         Range("a2").Resize(UBound(temp,1)).Value = temp
    Else
         Range("a2").Value = temp
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,226
Messages
6,164,709
Members
451,911
Latest member
Sam1am

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