How to make a message windo pop up with a message if cell value exceeds

Marq

Well-known Member
Joined
Dec 13, 2004
Messages
914
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Using Excel 2007

What would be the code or formula to make a message window pop up if a value of one cell exceeds the value of another?

For example:

Cell A20 has the value of 35 (the 35 is a total allowable man power number).

Cell A21 is the value of a sum of a range of cells (the range of cells, A3:A18, is where I plug the man power numbers)

I would like to have a window pop up with a message saying "Stop! Over Allocated" when cell A21 exceeds the value of cell A20.


This same formal/code will also have to be applied to multiple columns..not just column A.

The columns A, B & C are for individual craft titles....so as I plug numbers in column A for Craftsman Level 1, and I eventually exceed the value of cell A20 I get a pop up indicating I've overallocatted man power for Craftsman level 1.....I would then go back and of course adjust my numbers not to exceed cell A20.......once corrected, I can then move to column B for Craftsman Level 2 and begin the same process...and so on and so on.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Does something like this help?

I pasted it into "This Workbook" in the VBA window.

This is prob not the easiest way of doing it but it does show a message box if the Value in A21 is greater than the value in A20 and highlights it also.

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim A21 As Integer
Dim A20 As Integer
A21 = Worksheets("Sheet1").Range("A21")
A20 = Worksheets("Sheet1").Range("A20")
If A21 > A20 Then
    MsgBox "Stop! Over Allocated For A"
    With Worksheets("Sheet1").Range("A21").Interior
    .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End If
If A21 < A20 Then
With Worksheets("Sheet1").Range("A21").Interior
     .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top