Hello,
I am trying to use data validation in order to avoid that user write a value higher than 100 nor lesser than 0 in certain cells.
I previously give format to the cells with the following code:
Worksheets("Sheet1").Range(Cells(12, 6), Cells(lastrow, 56)).NumberFormat = " #,##0.0%_ ; -#,##0.0%_ ; """"??_ ;_-@_ "
Let's say that "lastrow" is 50.
Afterwards, I call the following function:
Sub aavalidation(lastrow as integer)
Worksheets("Sheet1").Range(Cells(12,6),Cells(lastrow, 56)).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertInformation, _
Operator:=xlBetween, Formula1:="0", Formula2:="100"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Invalid HC value"
.InputMessage = ""
.ErrorMessage = "The HC data you entered isn't a valid value."
.ShowInput = True
.ShowError = True
End With
End Sub
When this code is executed I receive the 1004 Run-time error (Application-defined or Object Defined Error) and the debugging says that the problem is in:
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertInformation, _
Operator:=xlBetween, Formula1:="0", Formula2:="100"
I would much appreciate your assistance in this issue.
Bookmarks