Validation Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I disallow certain characters in a cell? I don't want the user to
enter single quotations, commas, and & in the cells of a particular column.
 
Here is some code that will catch when a user enters a value with one of the
offending characters in column B (2)...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim blnIsOk As Boolean

blnIsOk = True
If Target.Column = 2 Then
If InStr(1, Target.Value, "'") Then
blnIsOk = False
ElseIf InStr(1, Target.Value, ",") Then
blnIsOk = False
ElseIf InStr(1, Target.Value, "&") Then
blnIsOk = False
End If
End If

If Not blnIsOk Then
MsgBox "That is not a valid input."
Application.Undo
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top