Warning message

BarnBrian

Board Regular
Joined
Oct 2, 2005
Messages
109
I want to have a warning message appear when a particular cell function result is a specific number, probably very simple to achieve.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
That requires some VBA - which I can show you how to do. Are you up for i?

It is a fairly simple to achieve so is a good place to start if you've never done it before. (I'm assuming you're relatively new to it from the phrasing of your question, my apologies if that's incorrect.)
 
Upvote 0
Yes I'm up for it. Correct I am a VBA beginner, I just can't seem to get past first base to follow the logic of how to write simple code.
Thanks in advance.
 
Upvote 0
Okay... here goes.

Press Alt - F11 to bring up the VBA editor.

In the Project box at the left hand side select:
Sheets(YourPRojectName) / Microsoft Excel Objects / This Workbook
and double click.

Paste in this code:


Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

If Range("B10").Value = 1 Then
    
    Range("B10").Value = "Some other Value"
    Range("B10").Select

    MsgBox "Warning, Warning, Explosion Immminent", vbOKOnly + vbExclamation, "A helpful little box"
    
End If


End Sub

This will, every time a new cell is selcted, check the value of cell B10. If B10 is = 1 then it will be reset to the phrase "some other value", then selected, then a message box appears with my whimsical warning.

Under this configuration, you cannot leave the "bad" value in the cell. Is this what you wanted?

Obviously you need to replace B10, 1, and the messages as appropriate to your circumstance.

Philip
 
Upvote 0
Thanks Philip, had to alter it slightly to suit my needs but I feel I actually learned something, have a Tooheys old on me.

Brian
 
Upvote 0
You're welcome - ironically enough Tooheys old is one of my favourites... Though the Lord Nelson brewery does an even better black beer I've recently discovered.

Happy to help!

Philip
 
Upvote 0
Philip
How do I go about locking the macro so that others can't alter or view it.
I would have thought that locking the worksheet would have done it but that's obviously not the case.

Brian
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

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