PDA

View Full Version : Solved: Prompt User if user enters a character



Emoncada
02-28-2012, 08:17 AM
I want to be able to test Cell A2 if a user enters a "#" then have it prompt the user "Invalid Character Entered" with an OK button

JKwan
02-28-2012, 08:31 AM
Try this:
Private Sub Worksheet_Change(ByVal Target As Range)
If (Not Intersect(Target, Range("A2")) Is Nothing) Then
If InStr(1, Target.Value, "#") Then
Application.ScreenUpdating = False
MsgBox "Invalid Character Entered", vbOKOnly, "Invalid Character"
Range("A2").Select
Application.ScreenUpdating = True
End If
End If
End Sub

Emoncada
02-28-2012, 08:33 AM
Sorry I meant if cell contains a "#" in it, not just "#"

JKwan
02-28-2012, 08:35 AM
just remove the INTERSECT like this:
Private Sub Worksheet_Change(ByVal Target As Range)
If InStr(1, Target.Value, "#") Then
Application.ScreenUpdating = False
MsgBox "Invalid Character Entered", vbOKOnly, "Invalid Character"
Target.Select
Application.ScreenUpdating = True
End If
End Sub

Emoncada
02-28-2012, 08:37 AM
Actually That worked.

Emoncada
02-28-2012, 09:07 AM
Thanks JKwan

shrivallabha
02-28-2012, 10:29 AM
You could also use Data Validation like:
Data Validation | Custom (Formula as below)
=NOT(ISNUMBER(FIND("#",A2,1)))