Pop-Up Message for only when a cell's value changes and not when other cells change

lucy61176

New Member
Joined
Jun 11, 2014
Messages
22
I want to create a pop-up message for two of the cells that contain a formula. Cell A10 counts dates entered in column A for the current calendar year. E10 totals the hours and minutes in column E. I was able to create the following code:



Private Sub Worksheet_Calculate()
If Range("A10").Value > 3 Then MsgBox "Employee has reached the tardy threshold. Contact HR Coordinator."
If Range("E10").Value > 2.667 Then MsgBox "Employee has reached the 64-hour threshold for sick leave. Contact HR Coordinator. If employee provides medical verification, enter hours over 64, using calculator on the right, in a new row under the Pre-Approved and Authorized Absences section."
End Sub



I would like it to pop up when the total is => a certain value. I would not like it to pop up if data in other cells outside that column is entered (right now it seems to pop up once the condition is met everywhere on the sheet). If the user deletes rows and it makes the total < the certain value, I would not like it to pop up, but if the user adds more data again to make the total => the value, I would like it to pop up again. This is a dynamic, ever-changing sheet, but I am not sure how to make it work this way.
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,166
The Worksheet_Calculate event procedure is triggered when any formula is re-calculated on the worksheet.

Use the Worksheet_Change event procedure instead. It's triggered when the user changes the worksheet. The code below evaluates if the user-change occurred in column A or E and displays the appropriate message based on the values in A10 and E10.

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    [color=darkblue]If[/color] Target.Count = 1 [color=darkblue]Then[/color]
        [color=darkblue]If[/color] Target.Column = 1 [color=darkblue]Then[/color]       [color=green]'Column A changed[/color]
            [color=darkblue]If[/color] Range("A10").Value > 3 [color=darkblue]Then[/color] MsgBox "Employee has reached the tardy threshold. ", , "Contact HR Coordinator."
        [color=darkblue]ElseIf[/color] Target.Column = 5 [color=darkblue]Then[/color]   [color=green]'Column E changed[/color]
            [color=darkblue]If[/color] Range("E10").Value > 2.667 [color=darkblue]Then[/color]
                MsgBox "Employee has reached the 64-hour threshold for sick leave. " & vbLf & vbLf & _
                       "If employee provides medical verification, enter hours over 64, using calculator on the right, " & vbLf & _
                       "in a new row under the Pre-Approved and Authorized Absences section.", , _
                       "Contact HR Coordinator."
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 

Forum statistics

Threads
1,082,318
Messages
5,364,518
Members
400,804
Latest member
davileal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top