I am attempting to add data validation to a UserForm with textboxes. I need a way to have the userform alert the person entering data that an entry is out of range. This is for running hours of an engine and is entered daily, so 24 or less hours. I would also like to add in an alert for negative hours. This Userform has a number of textboxes so I would prefer just highlighting the specific textbox instead of a pop up message.
My current code, validates then enables Commandbutton1 to enter the data from the userform. Range("B17").Value is the worksheet cell with the previous days entry.
My current code, validates then enables Commandbutton1 to enter the data from the userform. Range("B17").Value is the worksheet cell with the previous days entry.
Code:
Private Sub Validate_Click()
ValidateDataDisplayLabel
End Sub
Sub ValidateDataDisplayLabel()
If PMEHours.Value - Range("B17").Value > 24 Then
PMEHours.BackColor = &HFF&
End If
CommandButton1.Enable
End Sub
Last edited: