VBA - MsgBox Based on Cell Value

GustavoSRP Posted messages 8 Status Member -  
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   -
Hello everyone,

Thank you in advance for your help.
I am a beginner with VBA in Excel.
I need to display a MsgBox based on the value of a given range of cells.
For example:

If the values in the range (A1:A41) are greater than 29.99, a MsgBox should appear with a "text X"

Please take into account that there is a formula in the range of cells that gives the result.

A big thank you to everyone

Gustavo

3 answers

jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
Hello

What have you started?
What are you stuck on?

Focus on the private sub worsheet_change(target) event

Target contains the modified cell

All you have left to do is use some if... And you're good to go

--
Best regards,
Jordane
1
GustavoSRP Posted messages 8 Status Member
 
Thank you jordane45,
I will see if I can do something with your suggestion, although it doesn't tell me how I can make a MsgBox appear when a cell X exceeds the amount of 29.99.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
 
Hello, when should the message appear? Upon opening the file?
You write "the displayed values are greater than 29.99": do you want to display the message only if all values are greater?
0
GustavoSRP Posted messages 8 Status Member
 
Not necessarily upon opening the file.
The message should appear immediately when the value of a group of cells, for example (''A1:A50''), exceeds this figure.
Exactly, I want the message to appear only if the value is greater than 29.99.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > GustavoSRP Posted messages 8 Status Member
 
What causes the values to change? What do the formulas contain?
There are 41 values, you didn't specify whether you wanted to receive a message as soon as any one of the values exceeds 29.99, or if all of them should exceed that.
0
GustavoSRP Posted messages 8 Status Member
 
The values of each cell change because each cell refers to another cell that performs an addition. The cell in question calculates the average amount over 52, for example.

Cell A1 contains the following formula: =B1/52
Cell B1 contains the following formula: SUM(B2:B12)

When cell A1 exceeds 29.99, a text message must appear.

So, when one or more cells in the range (''A1:A50'') reach 30 or more, the text message is displayed.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
And the message will start displaying again as long as one of the cells exceeds 30?
0
GustavoSRP Posted messages 8 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
 
Good question, the message should appear only once per cell and the message should indicate which cell it refers to.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > GustavoSRP Posted messages 8 Status Member
 
You should record somewhere (in a cell somewhere) whether or not to display the message.
Since you are a beginner in VBA, I suppose you can do that.
0