+ Reply to Thread
Results 1 to 8 of 8

Warning when negative number is calcuated across a range of cells

  1. #1
    Registered User
    Join Date
    05-20-2020
    Location
    Bristol, England
    MS-Off Ver
    2010
    Posts
    4

    Warning when negative number is calcuated across a range of cells

    I have a workbook which calculates stock levels based on a series of calculations. I need a warning box to pop up whenever the "Stock Total" goes negative, as this is something that isn't possible.

    I have managed to find a few methods of getting it to work when a value is entered manually, however the "Stock Total" is calculated from cells across different worksheets.

    Any help appreciated!

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Warning when negative number is calcuated across a range of cells

    You can do this without VBA.

    Something like in an appropriate empty cell:

    =IF(A1<0,"Stock Level Below Zero","")

    where A1 is the cell containing the stock level.

    It can be adapted to look at the last entry in a range if necessary.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Warning when negative number is calcuated across a range of cells

    Do you really need a warning box, that could be VBA

    Conditional formats to highlight the cell if this happens, format only cells that contain cell value < 0 and choose perhaps a red fill
    or/and an if statement =if(cell with total <0,"Error Negative Value","") are simpler to implement

  4. #4
    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: Warning when negative number is calcuated across a range of cells

    Hi,

    You'll need a Sheet Calculate event to capture that event. Name the Total stock cell say "TotalStock"

    Then create the following macro in the worksheet that contains the Total Stock - assumed to be the 'Sheet1' VBA code name (NOT the sheet tab name) in this code

    Please Login or Register  to view this content.
    Alternatively without a macro you could put a Conditional format in the Total Stock cell so that it changes to say red when it's <0
    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.

  5. #5
    Registered User
    Join Date
    05-20-2020
    Location
    Bristol, England
    MS-Off Ver
    2010
    Posts
    4

    Re: Warning when negative number is calcuated across a range of cells

    Hi Ali, thanks for the suggestion. Unfortunately I need to apply it to 40+ lines in one table. I have already made the cell obvious there is an error (making it highlight red) but this isn't working well enough to make people look at what's causing the error.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Warning when negative number is calcuated across a range of cells

    40+ lines isn't hard - add the formula to the adjacent column and simply drag copy down. It will take seconds.
    Attached Files Attached Files
    Last edited by AliGW; 07-01-2020 at 04:10 AM.

  7. #7
    Registered User
    Join Date
    05-20-2020
    Location
    Bristol, England
    MS-Off Ver
    2010
    Posts
    4

    Re: Warning when negative number is calcuated across a range of cells

    Hi Richard, thanks. I have conditionally formatted the cells already to highlight red when they go negative however this doesn't stop the values being left there.

    Does your solution apply to a single cell? I need it to apply to any cell in a range which goes negative. I tried it and nothing happened.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,007

    Re: Warning when negative number is calcuated across a range of cells

    this doesn't stop the values being left there
    What does this mean?

+ 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. [SOLVED] IF(AND(OR fx with positive and negative number range
    By brose99 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-29-2019, 03:07 AM
  2. [SOLVED] Sum if sum of cell range is negative number
    By TreeLife in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-24-2018, 06:25 AM
  3. Replies: 2
    Last Post: 09-24-2018, 12:51 PM
  4. [SOLVED] Delete all negative Number in a range.
    By bennyys in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2017, 01:24 PM
  5. Replies: 1
    Last Post: 11-20-2008, 01:52 AM
  6. Range less than/.. min/max to a negative number..
    By nastech in forum Excel General
    Replies: 2
    Last Post: 03-01-2006, 04:25 AM
  7. [SOLVED] Find a negative number in a range
    By Scott at Culvers in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-22-2005, 01:00 PM

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