+ Reply to Thread
Results 1 to 7 of 7

How to keep user from accidentaly deleting default-value formulas?

  1. #1
    Registered User
    Join Date
    02-09-2012
    Location
    Philippines
    MS-Off Ver
    2003
    Posts
    9

    How to keep user from accidentaly deleting default-value formulas?

    I have a cell containing this formula:

    =IF(ISBLANK(A4), "", "0.00")

    Basically, if A4 is empty, then the cell is also empty. But if A4 isn't, the default value should be 0.00. The user can edit that value though, and hence can delete what he entered, but even the formula gets deleted from the cell. How do I allow the user to modify the default value without letting him delete the underlying formula in the cell? Thanks

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: How to keep user from accidentaly deleting default-value formulas?

    You don't do this with formula but right click -> Format cell and then format it as number with 2 decimal places.

  3. #3
    Registered User
    Join Date
    02-09-2012
    Location
    Philippines
    MS-Off Ver
    2003
    Posts
    9

    Re: How to keep user from accidentaly deleting default-value formulas?

    Well, formatting it as a number with 2 decimal places doesn't make it show a default value 0.00 when A4 isn't empty. It only formats the numbers into that cell into a floating-point number with two decimal places, with rounding-off rules.

  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,463

    Re: How to keep user from accidentaly deleting default-value formulas?

    Unlock all the cells where you allow people to enter data, then protect the sheet with a password.

    You can choose whether or not to allow people to select the locked cells.

    Note that putting 0.00 in quotes as "0.00" gives you a default text value not a numeric value. Might or might not cause issues depending on what formulae refer to it.


    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


  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to keep user from accidentaly deleting default-value formulas?

    Hello,

    I think the confusion lies in a completely different quadrant.

    An Excel cell holds either a formula or a constant (text or number). You cannot use a cell for both. If you enter a number into a cell that has a formula, then the formula will be overwritten.

    You could use another cell where the user enters a value, let's say B4, and then your formula would be:

    =IF(ISBLANK(A4), "", B4)

    When A4 has a value, the formula will return the contents of cell B4. If B4 is empty, it will return a zero. Format the cell to have two decimal figures and teach your users to enter any variation from the default in cell B4.

    cheers,

  6. #6
    Registered User
    Join Date
    02-09-2012
    Location
    Philippines
    MS-Off Ver
    2003
    Posts
    9

    Re: How to keep user from accidentaly deleting default-value formulas?

    ^Thanks for clarifying the problem, teylyn. However, is what I want to achieve still possible with macros? I was told I might be able to catch an onChange event or something. Sorry, I have absolutely no background in Excel VBA as my main expertise is in Java.

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: How to keep user from accidentaly deleting default-value formulas?

    Hello,

    yes, it is possible to use Worksheet_Change event to monitor specific cells and do things when the cells are edited. I don't quite understand what you want to achieve, though. Could you step back and explain the bigger picture?

    As far as I understand it, the requirements are like this:

    - if A4 is empty, cell "X" should be blank.
    - As soon as a value is entered in A4, cell "X" should show 0.
    - The user should be able to enter a value into cell "X", overwriting the 0
    - when the value in A4 is deleted, so A4 is blank again, cell "X" should be blank again as well

    The following Worksheet_Change Event performs this. Cell "X" in this case is B4, which is an offset of 0 rows and 1 column starting from A4. Change the offset to suit your needs

    Please Login or Register  to view this content.
    The attached file has the macro installed. Play around with the values in A4 and B4 and see if that is what you need.

    Does that give you a starting point?

    If you need to enhance this and get stuck, please pipe up. Clearly formulated requirements will help find a solution faster.

    cheers,



    ---------------------
    Worksheet event code is stored on a worksheet module. To add it to your worksheet, do the following:

    Copy the code
    Select the worksheet in which you the code to run
    Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
    Where the cursor is flashing, choose Edit | Paste
    Attached Files Attached Files

+ 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