+ Reply to Thread
Results 1 to 8 of 8

Prevent formula deletion without using locked cells and sheet protection

  1. #1
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Prevent formula deletion without using locked cells and sheet protection

    Whilst reading this extremely useful tip by John Walkenbach - see http://j-walk.com/ss/excel/usertips/tip045.htm for identifying cells with formulae, it set me thinking about the subject of preventing formula deletion.

    There is of course the standard Excel Worksheet Protection and cell locking combination, whereby all cells are protected unless they are unlocked when worksheet protection is set.

    However I’ve always found this somewhat of a nuisance when non formulae cells which need unlocking are dotted all over the place and not in simple contiguous ranges where they can be unblocked en bloc. And how many times have we found code tripping up when it needs to do something in a protected sheet, necessitating pairs of Sheet.Unprotect & Sheet.Protect code lines to prevent this. It happens to me all the time.

    So after some thought I wrote the following code.

    First the caveat. This is a VBA procedure so clearly if the user chooses not to enable macros this won't work.

    It's currently set to prevent formula deletion without exception.
    If it's necessary to warn the user first and then allow formula deletion if required then uncomment the five lines of the second IF..End If section (marked Option 1) and comment out the Option 2 line.

    It's a Worksheet_Change event, but equally the same code could be put in a Workbook_SheetChange event where it would kick in on any sheet rather than a specific sheet.

    Regards
    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 11-17-2012 at 02:03 PM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  2. #2
    Forum Contributor dogberry's Avatar
    Join Date
    07-15-2012
    Location
    Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    624

    Re: Prevent formula deletion without using locked cells and sheet protection

    Hi

    I read somewhere that you can stop people from changing formula in most instances by making it an array formula is that correct or have I read a load of rubbish.


    Chris
    Click my star if I helped Thanks

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Prevent formula deletion without using locked cells and sheet protection

    Hello Chris,

    I've certainly not heard of that one. Not quite sure why that would apply since an array formula/function is just a normal standard excel function albeit it with some special properties.

    Rgds,

  4. #4
    Forum Contributor dogberry's Avatar
    Join Date
    07-15-2012
    Location
    Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    624

    Re: Prevent formula deletion without using locked cells and sheet protection

    Hi

    Thanks I thought it might be a load of gibberish which is a language I understand perfectly

    Chris

  5. #5
    Registered User
    Join Date
    11-17-2012
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Prevent formula deletion without using locked cells and sheet protection

    Hi

    Is there an option when you adjust a formula theres comes a box where you can choose yes or no?

    Renato

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Prevent formula deletion without using locked cells and sheet protection

    Quote Originally Posted by Mase723 View Post
    Hi

    Is there an option when you adjust a formula theres comes a box where you can choose yes or no?

    Renato
    Hello Renato,

    Yes, that was covered in my original posting. Uncomment all the five option 1 lines of code and comment out the option 2 line.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Prevent formula deletion without using locked cells and sheet protection

    If you "array enter" a range of formulas - e.g. you select a range of cells, type a formula into one and then press CTRL+SHIFT+ENTER - you cannot change an individual formula in that range without changing or removing all of them. I've never used that type of entry before, so not sure what use it is.

    This does not affect individual cells containing array formulas, of course.

  8. #8
    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,463

    Re: Prevent formula deletion without using locked cells and sheet protection

    If you intend to enter a formula and then drag it down, you could, instead, select all the cells, enter the formula in the first cell, and commit with Ctrl-Shift-Enter. The formula will be propagated through the range.

    At face value, it has the same effect, however, you cannot change an individual cell in the range.


    Regards, TMS
    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


  9. #9
    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,463

    Re: Prevent formula deletion without using locked cells and sheet protection

    Sorry Paul, I may have just said the same thing as you ... just didn't read it the same.

    Regards, TMS

+ 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