+ Reply to Thread
Results 1 to 7 of 7

Thread: 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
    Excel 2007
    Posts
    6,216

    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.
    "Relax. What is mind? No matter. What is matter? Never mind!"

  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 TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,231

    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

  5. #5
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    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 Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,151

    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

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("A4")) Is Nothing Then
        If Target = "" Then
            Target.Offset(0, 1) = ""
        Else
            If Target.Offset(0, 1) = "" Then
                Target.Offset(0, 1) = 0
            End If
        End If
        
    End If
    
    End Sub
    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.2.0