Consulting

Results 1 to 6 of 6

Thread: Solved: BeforeDoubleClick Issue?

  1. #1

    Solved: BeforeDoubleClick Issue?

    Hello,

    I wrote this code to make it easier to organize rows in the active sheet. So with one double click the current row is cut-selected and with another double click the row will be inserted. I used Range("B1") value to differentiate between the first double click and the second double click. But the problem is when you hit Esc to cancel the selection (i.e. the first double click) the second double click is always carried out because the value of B1 is the same.
    How can I differentiate between the 1st and 2nd double clicks without having to set B1 value?

    [vba]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim RwNum As Long
    Dim DbCk As Integer

    DbCk = Range("B1").Value

    If ActiveCell.Value = "Not This Cell" Or ActiveCell.Row = 1 Then
    Exit Sub
    End If

    Select Case DbCk

    Case Is = 0
    RwNum = ActiveCell.Row
    Rows(RwNum).Select
    Selection.Cut
    Range("B1").Value = 1

    Case Is = 1
    Selection.Insert Shift:=xlDown
    Range("B1").Value = 0

    End Select

    End Sub[/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Probably off-beam as i don't uderstand what you are trying to do

    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Static DbCk As Boolean

    If Target.Value = "Not This Cell" Or Target.Row = 1 Then
    Exit Sub
    End If

    If Not DbCk Then

    Target.EntireRow.Cut
    Else
    Target.EntireRow.Insert Shift:=xlDown
    End Select
    DbCk = not DbCk

    Cancel = True

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Simply, what I want to do is cutting and inserting individual rows just by double clicking instead of having to (select the entire row then right clicking then choosing 'cut' command. Then selecting another row then right clicking then choosing 'insert cut cells' command).

    1st double click will cut the entire row, the 2nd double click will insert it.
    with the possibility to cancel the cut process after the 1st double click anytime so that the 2nd double click (inserting the row) is ignored.

    I hope I made myself clear, thank you xld.
    Last edited by Ctrl; 10-02-2009 at 09:57 AM.

  4. #4
    Thank you xld.
    Your code actually works exacatly the way I want it.
    I didn't notice that first because it gave an error.

    [vba]End Select[/vba] must be [vba]End If[/vba]
    It's my bad anyway.

    Your help is appreciated.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry about that, I just cut it from the original, and didn't test it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Now, it's more perfect. I figured out how to cancel the 2nd double click effect in case the Esc button was pressed after the 1st double click.

    [vba]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Static DbCk As Boolean

    If Target.Value = "Not This Cell" Or Target.Row = 1 Then Exit Sub

    If Not DbCk Then
    Target.EntireRow.Cut
    Else
    If Not Application.CutCopyMode = xlCut Then
    DbCk = Not DbCk
    Exit Sub
    Else
    Target.EntireRow.Insert Shift:=xlDown
    End If
    End If

    DbCk = Not DbCk
    Cancel = True

    End Sub[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •