Ironman
Well-known Member
- Joined
- Jan 31, 2004
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
Hi
I've created a simple message box when Col B in the bottom row of the expanding range below exceeds Col B in the row above it. The two cells are named ranges (I've placed them in cells so it's clear what they do - they're not actually in those cells) and it looks like this
What I'm after is a bit more code so the message box only pops up once.
Many thanks!
I've created a simple message box when Col B in the bottom row of the expanding range below exceeds Col B in the row above it. The two cells are named ranges (I've placed them in cells so it's clear what they do - they're not actually in those cells) and it looks like this
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range ("thisyr") > Range ("lastyr") then msgbox "Last year's total exceeded!"
End Sub
Book1.xlsm | ||||
---|---|---|---|---|
A | B | |||
1 | YEAR | TOTAL | ||
2 | 1984 | 5 | ||
3 | 1986 | 12 | ||
4 | 1987 | 10 | ||
5 | 1988 | 1 | ||
6 | 1989 | 6 | ||
7 | 1990 | 2 | ||
8 | 1991 | 3 | ||
9 | 1993 | 1 | ||
10 | 1994 | 8 | ||
11 | 1996 | 5 | ||
12 | 1998 | 1 | ||
13 | 2000 | 7 | ||
14 | 2001 | 1 | ||
15 | 2002 | 6 | ||
16 | 2003 | 12 | ||
17 | 2004 | 24 | ||
18 | 2005 | 9 | ||
19 | 2006 | 2 | ||
20 | 2007 | 22 | ||
21 | 2008 | 3 | ||
22 | 2019 | 27 | ||
23 | 2020 | 11 | ||
24 | 2021 | 32 | ||
25 | ||||
26 | TOTAL | 210 | ||
27 | ||||
28 | Last Yr | 11 | ||
29 | This Yr | 32 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B26 | B26 | =SUM(B2:B25) |
B28 | B28 | =LastYr |
B29 | B29 | =ThisYr |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
LastYr | =OFFSET(Sheet1!$B$24,-1,0) | B26 |
ThisYr | =OFFSET(Sheet1!$B$25,-1,0) | B28, B26 |
What I'm after is a bit more code so the message box only pops up once.
Many thanks!