VBA - If cell value exceeds a certain number I would like a message box to appear

Simbo2012

Board Regular
Joined
May 28, 2012
Messages
55
Hi all,

Currently trying to put together a bit of code that returns a message box if a cell exceeds a certain number.

Here it is:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
If Range("C8").Value > 10249 Then
MsgBox ("The last batch number in this range has been reached. Please complete the following steps:" & vbCrLf & _
"- Delete the last line of information entered" & vbCrLf & _
"- Open the associated Batch Numbers spreadsheet" & vbCrLf & _
"- Manually delete the dates and job numbers currently against the batch numbers")
ElseIf Range("C9").Value > 10249 Then
MsgBox ("The last batch number in this range has been reached. Please complete the following steps:" & vbCrLf & _
"- Delete the last line of information entered" & vbCrLf & _
"- Open the associated Batch Numbers spreadsheet" & vbCrLf & _
"- Manually delete the dates and job numbers currently against the batch numbers")
End If
End Sub

However no message box is appearing if the cells hit 10250. What am I doing wrong?

(I am also trying to achieve line breaks in the message box).
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Simbo2012,

Your code does not even get a chance to run, see the BOLD line:

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
If Range("C8").Value > 10249 Then

'the rest of your code follows.....



Try the following:

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' hiker95, 01/22/2014, ME752093
If Intersect(Target, Range("C8:C9")) Is Nothing Then Exit Sub
If Target.Value >= 10249 Then
  MsgBox ("The last batch number in this range has been reached. Please complete the following steps:" & vbCrLf & _
    "- Delete the last line of information entered" & vbCrLf & _
    "- Open the associated Batch Numbers spreadsheet" & vbCrLf & _
    "- Manually delete the dates and job numbers currently against the batch numbers")
End If
End Sub


Remember, the same worksheet can only have one Worksheet_SelectionChange event.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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