View Full Version : custom error message box
im looking for some code to display a custom message box (form) when the user types anything else other than the letter "x" in columns a:k
 
can anybody help me with this?
 
thanks.
MaximS
02-07-2010, 10:25 AM
try that:
 
 
Private Sub Worksheet_Change(ByVal Target As Range)
        
Dim Err As String
If Target.Column > 11 Then
Exit Sub
Else
    If Target.Value <> "x" Then
       Err = MsgBox("Only allowed value is x", vbCritical + vbOKOnly, "Wrong value")
    End If
End If
End Sub
thanks! that works perfectly except if the user deletes the x the msg still pops up.  is there a way for that not to happen?
lucas
02-07-2010, 11:58 AM
Private Sub Worksheet_Change(ByVal Target As Range)
     
    Dim Err As String
    If Target.Column > 11 Then
        Exit Sub
    Else
        If Target.Value <> "x" And Target.Value <> "" Then
            Err = MsgBox("Only allowed value is x", vbCritical + vbOKOnly, "Wrong value")
        End If
    End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.