VALIDATION FUNCTION HELP 2...

  • Thread starter Thread starter KLZA
  • Start date Start date
K

KLZA

How can I use validation to stop users from entering the following
characters?: / \ : * ? " < > |
 
Place this code on the sheet you wish to bar the entry on in the Microsoft
Excel Objects Section of the VBAProject:

Public DontCall As Integer
Public LastCol As Double
Public LastRow As Double


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim X As Double
Dim ans As Variant
If DontCall = 1 Then
DontCall = 0
GoTo endingout
End If
If LastRow = 0 Then
LastRow = ActiveCell.Row
End If
If LastCol = 0 Then
LastCol = ActiveCell.Column
End If
X = 0
Let X = InStr(1, Cells(LastRow, LastCol).Value, "/")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Forward Slash (/). Please
change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, "\")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a BackSlash (/). Please
change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, "*")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Splat (*). Please
change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, Chr(34))
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Double Quotation Mark.
Please change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, "<")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Less Than Symbol (<).
Please change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, ">")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Greater Than Symbol
(>). Please change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If
If X = 0 Then
Let X = InStr(1, Cells(LastRow, LastCol).Value, "|")
If X > 0 Then
ans = MsgBox(prompt:="You should NOT enter a Pipe Symbol (|).
Please change it!", Title:="Big Problem!", Buttons:=vbCritical)
DontCall = 1
Cells(LastRow, LastCol).Select
GoTo endingout
End If
End If


LastRow = ActiveCell.Row
LastCol = ActiveCell.Column

endingout:


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