Display Message Box only once when value exceeded

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. 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
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
AB
1YEARTOTAL
219845
3198612
4198710
519881
619896
719902
819913
919931
1019948
1119965
1219981
1320007
1420011
1520026
16200312
17200424
1820059
1920062
20200722
2120083
22201927
23202011
24202132
25
26TOTAL210
27
28Last Yr11
29This Yr32
Sheet1
Cell Formulas
RangeFormula
B26B26=SUM(B2:B25)
B28B28=LastYr
B29B29=ThisYr
Named Ranges
NameRefers ToCells
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!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How often do you want it to appear ??
Why not use a worksheet_activate code so it appears every time you open the worksheet ?
 
Upvote 0
Hi Michael, thanks for replying - I'd really like the message box to appear just once, when the data that triggers the increase has been entered in Col D of another sheet (it then copies to the above range and increases the value of ThisYr). As it will remain greater for the rest of that year I don't want to be reminded every time I open the worksheet.
 
Upvote 0
So, you want the msg box to appear when data is changed in a different sheet. Is that correct ?
If so, include the message in the OTHER sheet code, so when col "D" of that sheet changes the sheet code on that sheet will show the message.
 
Upvote 0
Yes, that's correct.
OK, thanks, that makes sense, but I still don't know how to make the message box pop up only once, as any other change event will trigger it again.
 
Upvote 0
Well, I'm assuming it is only certain data on the other sheet that is relative to the outcome.
So in the sheet code on the other sheet mak it only applicable to changes in that data and nothing else !!
As we don't know what cells are affected on Which sheet, we can't write it for you !
If there is already a worksheet event in the other sheet we would need to see that as well !!
 
Upvote 0
Yes, that's correct.
OK, thanks, that makes sense, but I still don't know how to make the message box pop up only once, as any other change event will trigger it again.
You may be able to use a static counter so that the msg pops up only once during the period the workbook is open. Closing the workbook will reset the counter to zero so a subsequent opening may trigger the pop-up again if the critical cell(s) are changed manually. As Michael points out you need to provide more info if you are looking for sheet code to be written.
 
Upvote 0
OK thanks a lot Michael and Joe once again, you've both explained that it's not as simple as I thought it might be (yes Michael, I need a beginner's course on VBA...!). It's not a problem though, I'll just use some conditional formatting instead to highlight the cell.

Thanks again both of you for your input.
 
Upvote 0
OK thanks a lot Michael and Joe once again, you've both explained that it's not as simple as I thought it might be (yes Michael, I need a beginner's course on VBA...!). It's not a problem though, I'll just use some conditional formatting instead to highlight the cell.

Thanks again both of you for your input.
You are welcome - glad we could help.
 
Upvote 0
Hi Michael, thanks for replying - I'd really like the message box to appear just once, when the data that triggers the increase has been entered in Col D of another sheet (it then copies to the above range and increases the value of ThisYr). As it will remain greater for the rest of that year I don't want to be reminded every time I open the worksheet.
You could use a 'helper cell' somewhere in a sheet to store a value, and then check if that value has been set prior to displaying msgbox. ;)

Might look something like this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If HelperCell <> Something And Range("thisyr") > Range("lastyr") Then MsgBox "Last year's total exceeded!"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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