+ Reply to Thread
Results 1 to 7 of 7

Application undo after a cell was moved

  1. #1
    Registered User
    Join Date
    11-12-2015
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    16

    Application undo after a cell was moved

    Hello, I need help with this. I want to prevent cell A1 to be modified, and I use this code:

    Please Login or Register  to view this content.
    This code works, but when I cut the cell A1 and paste it to another cell, the code does not work anymore. The cell A1 become clear and its value move to the cell I paste it.
    Last edited by Mike911; 05-25-2016 at 06:03 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Application undo after a cell was moved

    VBA code does not update references when a cell is moved... or after rows/columns are inserted/deleted.

    You don't give enough information to suggest a possible workaround.

  3. #3
    Registered User
    Join Date
    11-12-2015
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    16

    Re: Application undo after a cell was moved

    Quote Originally Posted by cytop View Post
    VBA code does not update references when a cell is moved... or after rows/columns are inserted/deleted.

    You don't give enough information to suggest a possible workaround.
    I want the cell A1 to can not be moved. I want Application.Undo to work in this situation, or to disable in some way the "Cut" function only for cell A1.
    Last edited by Mike911; 05-25-2016 at 07:13 AM.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Application undo after a cell was moved

    A subtle difference I didn't fully understand myself.

    What you'll have to do is store the contents of A1 somewhere and then check that A1 is still equal to the stored value after every change. For example, paste the following into the worksheet code module.

    Please Login or Register  to view this content.
    Every time you move to a different cell, the variable CellA1 is checked to make sure it is not empty. The current value in A1 is saved if it is. After a change to the worksheet, the value in A1 is compared to the value of the variable and, if different, the change is undone.

    This is an example only, there are probably better ways to write it. for example you will have to update A1 before adding the code otherwise it will cancel any changes, it also rules out any code you may have updating A1.

    In the end, though, everything can be worked through.
    Last edited by cytop; 05-25-2016 at 07:23 AM.

  5. #5
    Registered User
    Join Date
    11-12-2015
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    16

    Re: Application undo after a cell was moved

    Works, thank you so much for help.

  6. #6
    Registered User
    Join Date
    11-12-2015
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    16

    Re: Application undo after a cell was moved

    Another thing. It is possible to Private an array as Variant in this situation ? For example: Private CellA2B5 as Variant and CellA2B5 to be array A2:B5.

  7. #7
    Registered User
    Join Date
    11-12-2015
    Location
    Romania
    MS-Off Ver
    2010
    Posts
    16

    Re: Application undo after a cell was moved

    One more problem, if the cell value is 0, the code does not work anymore. Is there a way to make this code (or another code) to work in this situation too ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 11-22-2014, 05:02 PM
  2. Application.Undo fails in a big VBA project
    By fadosolre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2013, 10:05 AM
  3. EXCEL: Application.Undo Error
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 01:22 AM
  4. Replies: 0
    Last Post: 02-29-2012, 01:40 PM
  5. Undo function to undo Visual Basic commands
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2010, 04:59 AM
  6. [SOLVED] Application.Undo failing with specific order of events
    By Bill P in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-03-2005, 03:05 PM
  7. Worksheet_Change and Application.undo
    By Mangesh Yadav in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2005, 08:05 AM

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