#excel #vba #validation
Вопрос:
на этом изображении сообщение об ошибке появляется перед проверкой данных, нажав на кнопку проверки
Sub condition() Dim id As Integer Dim name As String Dim the_date As Date Columns("A:A").Select If id gt;= 1 Then With Selection.Validation .Delete .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _ Operator:=xlGreaterEqual, Formula1:="1" .IgnoreBlank = True .InCellDropdown = True .ErrorTitle = "Invalid data" .ErrorMessage = "the id must be greter than 0" .ShowInput = True .ShowError = True End With ElseIf name = "" Then Columns("B:B").Select With Selection.Validation .Delete .Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop, _ Operator:=xlGreaterEqual, Formula1:="3" .IgnoreBlank = True .InCellDropdown = True .ErrorTitle = "invalid data" .ErrorMessage = "the name must have more than 3 letters " .ShowError = True End With Exit Sub ElseIf Date gt;= "1/1/2000" Then Columns("C:C").Select With Selection.Validation .Delete .Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="1/1/2000", Formula2:="12/30/2021" .IgnoreBlank = True .InCellDropdown = True .ErrorTitle = "invalid date" .ErrorMessage = "date must be between 1/1/2000 and 12/30/2021" .ShowError = True End With Else MsgBox "YOUR DATA ARE VALIED", vbApplicationModal End If End Sub
Комментарии:
1. Вы собираетесь использовать
the_date
? Кроме того, в чем проблема? Я не могу видеть изображение, так что, возможно, это проясняет ситуацию. Не могли бы вы подробнее объяснить, в чем проблема.