ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VALIDATION FUNCTION HELP 2... (https://www.excelbanter.com/excel-programming/411312-validation-function-help-2-a.html)

KLZA

VALIDATION FUNCTION HELP 2...
 
How can I use validation to stop users from entering the following
characters?: / \ : * ? " < |

Mike H.

VALIDATION FUNCTION HELP 2...
 
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


"KLZA" wrote:

How can I use validation to stop users from entering the following
characters?: / \ : * ? " < |



All times are GMT +1. The time now is 11:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com