how can I set a cell so that you can only type in 1 , 2 , 3, 4, 5
I know I can use the validation but people can just copy a cell and paste it over.
how can I set a cell so that you can only type in 1 , 2 , 3, 4, 5
I know I can use the validation but people can just copy a cell and paste it over.
Under allow > select whole numbers
Min 1
Max 5
VBA Noob
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
Either you can set up a validation (as you mentioned) AND protect your worksheet to prevent people from copying/pasting over the validation, or you can use VBA (if you don't mind that) to prevent people from entering an incorrect value.
Sorry
Misread the question.
See if link helps
http://www.j-walk.com/ss/excel/tips/tip98.htm
VBA Noob
Or a event macro. Right click sheet > select view code and paste in the below. Change range as required
VBA Noob![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1:A5")) Is Nothing Then If Target.Value > 5 Then Application.Undo MsgBox "Please enter number between 1 & 5" End If End If End Sub
Sorry where can I specify allow ?
See link point 3.
http://www.contextures.com/xlDataVal01.html#Apply
VBA Noob
HOW CAN I ADPAT THIS SO THAT Z3:Z500 IS RESTRICTED TO 1 , 2 OR 3 AS WELL AS THE ABOVE.![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1:A5")) Is Nothing Then If Target.Value > 5 Then Application.Undo MsgBox "Please enter number between 1 & 5" End If End If End Sub
Change to
VBA Noob![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("Z3:Z500")) Is Nothing Then If Target.Value > 3 Then Application.Undo MsgBox "Please enter number between 1 & 3" End If End If End Sub
This is just a minor change to VBA Noob's code to disallow decimal numbers from being used in place of whole numbers:
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("Z3:Z500")) Is Nothing Then If Target.Value > 3 Or Target.Value <> Int(Target.Value) Then Application.Undo MsgBox "Please enter number between 1 & 3" End If End If End Sub
Try
VBA Noob![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1:A5")) Is Nothing Then If Target.Value > 5 Then Application.Undo MsgBox "Please enter number between 1 & 5" End If End If If Not Intersect(Target, Range("Z3:Z500")) Is Nothing Then If Target.Value > 3 Then Application.Undo MsgBox "Please enter number between 1 & 3" End If End If End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks