D
D
Denis Mashanov2017-07-28 20:30:07
excel
Denis Mashanov, 2017-07-28 20:30:07

How to limit cell input?

Good afternoon everyone. I had such a problem. I need to be able to enter only numbers and one comma into a cell. I tried through formulas, but nothing happened, and if you try through a macro, you can turn off the macro, and then the user can enter whatever he wants. Please help.
It will be very good if everything is implemented through formulas using the data validation method in the cell.
That is, the cell content template should be only this (*,*), which means entering at least as many digits and only one comma, and the rest is unacceptable.
I need this so that a person can only enter data in a numerical format using only one comma if he wants to divide to kopecks and that's it. This method applies well to one cell, but to several.
Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Mashanov, 2017-07-30
@LoneRay

I did as I said in paragraph 2 of DS28.
Set to sheet.
Private Sub Worksheet_Calculate()
ActiveSheet.Range(Target.Address).NumberFormat = "@"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4:G54")) Is Nothing Then
Application.EnableEvents = False
If Not ActiveSheet.Range(Target.Address).NumberFormat = "@" Then
MsgBox "Необходимо использовать формат ячейки [Текстовый]", 48, "Ошибка"
Target = ""
Else
If Not IsNumeric(Target) And ActiveSheet.Range(Target.Address).NumberFormat = "@" Then
MsgBox "Разрешается ввод используя шаблон [1234,1234]", 48, "Ошибка"
Target = ""
End If
End If
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Range(Target.Address).NumberFormat = "@"
End Sub

A
Alexander, 2017-07-28
@NeiroNx

Select the desired range of cells
Data tab->Data Validation
Other
Formula=NUMBER(D1:D100)
specify the same range in the formula

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question