+ Reply to Thread
Results 1 to 6 of 6

My undo routine fails with drag and drop.

  1. #1
    serdar
    Guest

    My undo routine fails with drag and drop.

    I want to block user to make changes in multiple cells at a time (at certain
    circumstances but disregard it now).

    I have this code (in the change event procedure) to undo any changes occurs
    with multiple cells:

    ...........

    If undoing Then Exit Sub

    If undoing = 0 And (Target.Columns.Count > 1 Or Target.Rows.Count > 1) Then
    MsgBox "illegal operation."
    undoing = 1
    Application.Undo
    undoing = 0
    Exit Sub
    End If

    ...........


    ' undoing is declared globally.


    It works fine when i select 3 cells and hit delete, but when i drag and drop
    it doubles the undo and cells go to the dragged place.
    What to do? ( I am guessing that a "drag and drop" triggers the change event
    2 times. )

    Moreover, this way ( to undo with the help of the boolean undoing) seems
    ugly to me. Any suggestions?






  2. #2
    JE McGimpsey
    Guest

    Re: My undo routine fails with drag and drop.

    See

    http://j-walk.com/ss/excel/tips/tip23.htm


    In article <[email protected]>,
    "serdar" <[email protected]> wrote:

    > I want to block user to make changes in multiple cells at a time (at certain
    > circumstances but disregard it now).
    >
    > I have this code (in the change event procedure) to undo any changes occurs
    > with multiple cells:
    >
    > ..........
    >
    > If undoing Then Exit Sub
    >
    > If undoing = 0 And (Target.Columns.Count > 1 Or Target.Rows.Count > 1) Then
    > MsgBox "illegal operation."
    > undoing = 1
    > Application.Undo
    > undoing = 0
    > Exit Sub
    > End If
    >
    > ..........
    >
    >
    > ' undoing is declared globally.
    >
    >
    > It works fine when i select 3 cells and hit delete, but when i drag and drop
    > it doubles the undo and cells go to the dragged place.
    > What to do? ( I am guessing that a "drag and drop" triggers the change event
    > 2 times. )
    >
    > Moreover, this way ( to undo with the help of the boolean undoing) seems
    > ugly to me. Any suggestions?


  3. #3
    serdar
    Guest

    Re: My undo routine fails with drag and drop.

    Thanks.
    I am not worried about the changes that my routine does.
    Let me put it this way: How to block user from drag and drop? Because this
    makes my change event works 2 times (I'm not sure about this though.).


    "JE McGimpsey" <[email protected]>, haber iletisinde şunları
    yazdı:[email protected]...
    > See
    >
    > http://j-walk.com/ss/excel/tips/tip23.htm
    >
    >
    > In article <[email protected]>,
    > "serdar" <[email protected]> wrote:
    >
    > > I want to block user to make changes in multiple cells at a time (at

    certain
    > > circumstances but disregard it now).
    > >
    > > I have this code (in the change event procedure) to undo any changes

    occurs
    > > with multiple cells:
    > >
    > > ..........
    > >
    > > If undoing Then Exit Sub
    > >
    > > If undoing = 0 And (Target.Columns.Count > 1 Or Target.Rows.Count > 1)

    Then
    > > MsgBox "illegal operation."
    > > undoing = 1
    > > Application.Undo
    > > undoing = 0
    > > Exit Sub
    > > End If
    > >
    > > ..........
    > >
    > >
    > > ' undoing is declared globally.
    > >
    > >
    > > It works fine when i select 3 cells and hit delete, but when i drag and

    drop
    > > it doubles the undo and cells go to the dragged place.
    > > What to do? ( I am guessing that a "drag and drop" triggers the change

    event
    > > 2 times. )
    > >
    > > Moreover, this way ( to undo with the help of the boolean undoing) seems
    > > ugly to me. Any suggestions?




  4. #4
    JE McGimpsey
    Guest

    Re: My undo routine fails with drag and drop.

    You can put this in your Workbook_Open event, then toggle it on and off
    in your Workbook_Activate and Workbook_Deactivate events (so that it
    doesn't interfere with your users other workbooks):

    Private Sub Workbook_Open()
    Application.CellDragAndDrop = False
    End Sub


    In article <[email protected]>,
    "serdar" <[email protected]> wrote:

    > I am not worried about the changes that my routine does.
    > Let me put it this way: How to block user from drag and drop? Because this
    > makes my change event works 2 times (I'm not sure about this though.).


  5. #5
    serdar
    Guest

    Re: My undo routine fails with drag and drop.

    Can i test, whether the last action done is a drag and drop or not? I don't
    want to restrict drag and drop for all the worksheets in the workbook.


    "JE McGimpsey" <[email protected]>, haber iletisinde şunları
    yazdı:[email protected]...
    > You can put this in your Workbook_Open event, then toggle it on and off
    > in your Workbook_Activate and Workbook_Deactivate events (so that it
    > doesn't interfere with your users other workbooks):
    >
    > Private Sub Workbook_Open()
    > Application.CellDragAndDrop = False
    > End Sub
    >
    >
    > In article <[email protected]>,
    > "serdar" <[email protected]> wrote:
    >
    > > I am not worried about the changes that my routine does.
    > > Let me put it this way: How to block user from drag and drop? Because

    this
    > > makes my change event works 2 times (I'm not sure about this though.).




  6. #6
    JE McGimpsey
    Guest

    Re: My undo routine fails with drag and drop.

    I don't know of any way to test this.

    Instead of the Workbook_Activate and Workbook_Deactivate events, you
    could disable drag and drop for one worksheet only by placing the code
    in the Worksheet_Activate or Worksheet_Deactivate events.



    In article <[email protected]>,
    "serdar" <[email protected]> wrote:

    > Can i test, whether the last action done is a drag and drop or not? I don't
    > want to restrict drag and drop for all the worksheets in the workbook.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1