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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
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.
 

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
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
 

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
Jindon thaks
Code s/b:
Code:
Selection.Cut
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
thks to all
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
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
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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
 

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
Alexander Barnes your code is OK to move the whole row to the top.
Thx
 

Forum statistics

Threads
1,181,717
Messages
5,931,641
Members
436,796
Latest member
parthibanmuniswamy

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
Top