msgbox when cell has value higher than 750

CV899000

Board Regular
Joined
Feb 11, 2016
Messages
98
Hi,

I am trying to prompt a message box if value entered into a cell exceeds 750.

I can do that with this code:

Set Target = Me.Range("B12")

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value > 750 Then
MsgBox "Large number, please consider"
End If
End Sub

Now, the problem is that I have a macro button in this sheet, that resets values in "B9", which then should reset the value of "B12" to "Input data".
But when I hit the reset button, the message box prompts several times before the value of "B12" changes from the high number to "input data", how can I fix that?
I do not want the message shown when I reset the cells.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Now if I enter a high number, it prompts a message and I can close that. Good.

If I then want to reset the sheet, I press the reset button, but then the MsgBox "Large number again! reconsider!!!" prompts.
I do not want any msgbox to prompt when I press the reset button, can I write a code that just exits the sub instead of prompting the last msgbox?
 
Upvote 0
Easy fix actually. Now it works.

The code now looks like this:

If Target.Address = Range("B12").Address Then
If Target.Value > 750 And num < 750 Then
num = Target
MsgBox "Large number, please consider"
Exit Sub
End If
If Target.Value > 750 And num > 750 Then
num = 0
Exit Sub
End If
If Target.Value < 750 Then
num = 0
End If
 
Upvote 0
you proveded code where you deleted that if condition, well, try that
Code:
Dim num As Double

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B12").Address Then
If Target.Value > 750 And num < 750 Then
num = Target
    If MsgBox("Large number, run reset?", vbYesNo + vbQuestion) = vbYes Then
'you can call reset also here
'Call Reset
    End If
Exit Sub
End If
    If Target.Value < 750 Then
    num = 0
    End If
End If
End Sub
 
Last edited:
Upvote 0
well you need to insert if condition for line num=target, because if target is text you`ll get error like before
 
Upvote 0
The thing is,

When I reset I want it to say "Input data" in B12, which is not allowed by num=Target.
So I get the mismatch runtime error.

How do I allow the cell to contain text, but when changed, check that the entered number is not higher than 750?
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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