Results 1 to 3 of 3

Thread: [RESOLVED] Condition to check if a specific cell value exceeds some value

  1. #1

    Thread Starter
    New Member cavemanpz's Avatar
    Join Date
    Nov 2005
    Posts
    12

    Resolved [RESOLVED] Condition to check if a specific cell value exceeds some value

    In brief:

    I monitor a specific cell value for changes (Worksheet_Change event).

    If the cell value will exceed 10 000, I'd like to be informed about it (Msgbox "Your value has just exceeded 10 000").

    That's not all:

    I'd like to be informed about each time the cell value will exceed another 10 000 (a multiple of 10 000). For example (MsgBox "Your value has just exceeded another 10 000")


    For example:

    The value is:
    9 000 - nothing happens
    10 001 = 9 000 + 1 001 - Msgbox "Your value has just exceeded 10 000"
    11 000 = 10 001 + 999 - nothing happens
    15 000 = 11 000 + 4 000 - nothing happens
    20 100 = 15 000 + 5 100 - Msgbox "Your value has just exceeded another 10 000"
    20 500 = 20 100 + 400 - nothing happens

    etc.
    Last edited by cavemanpz; Jan 11th, 2006 at 04:39 AM.

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Condition to check if a specific cell value exceeds some value

    So what exactly is your problem? You seem to have it figured out already! You know where the Worksheet_Change event is. You just check the Target range to see which cell it is and then action accordingly.

    Is it that you only want to see the msgbox the first time that the cell exceeds 10000, and then only once when it exceeds 20000?

    All you need is some booleans as flags:

    VB Code:
    1. Public ten As Boolean
    2. Public twenty As Boolean
    3.  
    4. Private Sub Worksheet_Change(ByVal Target As Range)
    5. If Target.Row <> range("mycell").row Or Target.Column <> range("mycell").column Then Exit Sub
    6. If Target.Name = Range("mycell").Name Then
    7.     If Range("mycell") > 10000 And ten <> True Then
    8.         MsgBox "You have just exceeded 10000"
    9.         ten = True
    10.     End If
    11.     If Range("mycell") > 20000 And twenty <> True Then
    12.         MsgBox "You have just exceeded 20000"
    13.         twenty = True
    14.     End If
    15. End If
    16. End Sub


    Does that answer whatever your question was?

    zaza

  3. #3

    Thread Starter
    New Member cavemanpz's Avatar
    Join Date
    Nov 2005
    Posts
    12

    Resolved Re: Condition to check if a specific cell value exceeds some value

    Thank you for you reply zaza.

    I'm satisfied with the code below:

    VB Code:
    1. Option Explicit
    2. Dim boolStart As Boolean
    3.  
    4. Private Sub Worksheet_Calculate()
    5. Static curPreviousValue As Currency
    6.  
    7.    If Not boolStart Then
    8.       curPreviousValue = Range("score").Value
    9.       boolStart = True
    10.       Exit Sub
    11.    End If
    12.  
    13.    If (Range("score").Value \ 10000) <> (curPreviousValue \ 10000) Then MsgBox "You have just exceeded another 10 000"
    14.  
    15.    curPreviousValue = Range("score").Value
    16.  
    17. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width