ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   msgbox for invalid data (https://www.excelbanter.com/excel-programming/370304-msgbox-invalid-data.html)

TimN

msgbox for invalid data
 
Probably an easy question for the experts.
How can I create a MsgBox that would pop up to inform a user that they are
trying to enter data that is not allowed under the current condition?

Example:

Col A: Col B: Col C:
Day of week Status that day Hours of Regular Pay

Mon 8/7 Regular 8
Tues 8/8 Regular 8
Wed 8/9 Sick <<<<This cell (call it C5)
Thur 8/10 Sick is where I have the
Fri 8/11 Sick question

If the user types 8 in cell C5 above, I would like a MsgBox to pop up
because an employee can't get 8 hours of regular pay on a day they were coded
as out sick (cell B5). So under this scenario, only cells C3-C4 could
contain 8, cells C5-C7 should remain blank.

Any Ideas?
Thanks!

Simon Lloyd[_867_]

msgbox for invalid data
 

Just use data validation like this:

Sub NumberVal()
Range("A1:D10").Select
With Selection.Validation
..Delete
..Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop,
_
Operator:=xlLessEqual, Formula1:="7"
..IgnoreBlank = True
..InCellDropdown = True
..InputTitle = ""
..ErrorTitle = "Invalid Data Entry"
..InputMessage = ""
..ErrorMessage = "You must enter a number either 7 or below!"
..ShowInput = True
..ShowError = True
End With
End Sub

Change the range to suit!

regards,
Simon


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=571414



All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com