+ Reply to Thread
Results 1 to 6 of 6

Prevent Cell Deletion but allow editing and inserting

  1. #1
    Registered User
    Join Date
    12-08-2022
    Location
    North Carolina
    MS-Off Ver
    2016
    Posts
    3

    Post Prevent Cell Deletion but allow editing and inserting

    Hello,

    I am looking for a solution that would prevent users from deleting a given cell (shift down, up, left, etc.) to prevent shuffling of data across the sheet but I still would like the ability to have users to edit cells and insert rows.

    Any solutions?

    Thank you in advance for your help!

  2. #2
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Prevent Cell Deletion but allow editing and inserting

    is this what you are looking for
    Please Login or Register  to view this content.
    ]

  3. #3
    Registered User
    Join Date
    08-24-2022
    Location
    hugo
    MS-Off Ver
    13
    Posts
    40

    Re: Prevent Cell Deletion but allow editing and inserting

    In Excel VBA, you can prevent users from deleting a given cell by using the Protect method of the Range object. This method allows you to specify which actions users are allowed to perform on the protected cells, and which actions are not allowed.

    For example, the following code will protect a given cell (in this case, cell A1) and prevent users from deleting it:
    Please Login or Register  to view this content.
    The Protect method has several arguments that you can use to customize the protection behavior. In the code above, the Password argument is used to set a password that users must enter to unprotect the cells. The UserInterfaceOnly argument is used to specify that the protection applies only to user actions performed through the Excel user interface, and not to actions performed by VBA code. The AllowFormattingCells argument is used to allow users to format the cells (e.g., change the font or background color), and the AllowDeletingRows argument is used to prevent users from deleting rows containing the protected cells.

    Note that this solution will only prevent users from deleting the protected cell by using the "Delete" command. It will not prevent users from shifting the cells up, down, left, or right, or from deleting the cell by using other methods (e.g., by using the Cut or Clear commands). To prevent these actions, you will need to use additional VBA code to intercept and cancel them.

    You can find more information about the Protect method and the available arguments in the Excel VBA documentation. To access the documentation, in Excel, press Alt+F11 to open the Visual Basic editor, then go to Help > Microsoft Visual Basic Help. In the search box, type "Range.Protect" and press Enter to see the documentation for this method.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,522

    Re: Prevent Cell Deletion but allow editing and inserting

    @excelgirl84: please can you provide the reference for rng.Protect.

    AFAIAA, you lock or unlock cells/ranges. You Protect worksheets (and workbooks).
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    08-24-2022
    Location
    hugo
    MS-Off Ver
    13
    Posts
    40

    Re: Prevent Cell Deletion but allow editing and inserting

    Quote Originally Posted by TMS View Post
    @excelgirl84: please can you provide the reference for rng.Protect.

    AFAIAA, you lock or unlock cells/ranges. You Protect worksheets (and workbooks).
    rng.Protect is a method of the Range object in Microsoft Excel that can be used to protect the cells in a range. The Protect method takes a number of arguments that can be used to specify which operations should be allowed on the protected cells and to set a password to unprotect the cells.

    In the example above, the rng variable represents the cell at A1, and the Protect method is used to protect that cell with the password "mypassword". The UserInterfaceOnly argument is set to True, which means that the protection will only apply to changes made through the user interface, and not to changes made through VBA code. The AllowFormattingCells argument is set to True, which means that the user will be able to format the cells in the protected range. The AllowDeletingRows argument is set to False, which means that the user will not be able to delete rows in the protected range.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,522

    Re: Prevent Cell Deletion but allow editing and inserting

    @excelgirl84: have you tried to run the code you provided?Error 438 Message.jpg

+ 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: 20
    Last Post: 04-01-2020, 11:04 PM
  2. Prevent Use of Escape Key Whilst Editing Cell
    By wahbob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-24-2017, 10:19 AM
  3. Prevent workbook deletion or create the copy upon the deletion?
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2014, 04:35 PM
  4. Prevent row deletion and cell modification
    By theo.mani in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2014, 03:28 AM
  5. [SOLVED] Require Cell To Contain Minimum Of '1' And Prevent Deletion
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-07-2012, 12:07 PM
  6. Prevent deletion of cell content after writing
    By careso in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2009, 03:44 PM
  7. Prevent deletion of a cell with no cell protection
    By jman0707 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 10-31-2008, 09:58 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