Mister_joe
02-14-2014, 02:29 AM
Hi all,
I am trying to apply validation to a range of cells as follows:
Private Sub Worksheet_Activate()
With Range("A1:D4").Validation
.IgnoreBlank = True
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertWarning, Operator:=xlBetween, Formula1:="0", Formula2:="50000"
.InputTitle = "Numeric"
.ErrorTitle = "Numeric"
.InputMessage = "Enter a number between 0 and 50,000"
.ErrorMessage = "You must enter a number between 0 and 50,000"
End With
End Sub
When I executed the code, I got the following error message:
Run-Time error '1004'
Application-defined or object-defined error
Thereafter, I move the code the Open event of the Workbook as follows:
Private Sub Workbook_Open()
With Range("A1:D4").Validation
.IgnoreBlank = True
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertWarning, Operator:=xlBetween, Formula1:="0", Formula2:="50000"
.InputTitle = "Numeric"
.ErrorTitle = "Numeric"
.InputMessage = "Enter a number between 0 and 50,000"
.ErrorMessage = "You must enter a number between 0 and 50,000"
End With
End Sub
I got the same error message. So, I wish to know in what context I am supposed to use validation.
Thanks.
I am trying to apply validation to a range of cells as follows:
Private Sub Worksheet_Activate()
With Range("A1:D4").Validation
.IgnoreBlank = True
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertWarning, Operator:=xlBetween, Formula1:="0", Formula2:="50000"
.InputTitle = "Numeric"
.ErrorTitle = "Numeric"
.InputMessage = "Enter a number between 0 and 50,000"
.ErrorMessage = "You must enter a number between 0 and 50,000"
End With
End Sub
When I executed the code, I got the following error message:
Run-Time error '1004'
Application-defined or object-defined error
Thereafter, I move the code the Open event of the Workbook as follows:
Private Sub Workbook_Open()
With Range("A1:D4").Validation
.IgnoreBlank = True
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertWarning, Operator:=xlBetween, Formula1:="0", Formula2:="50000"
.InputTitle = "Numeric"
.ErrorTitle = "Numeric"
.InputMessage = "Enter a number between 0 and 50,000"
.ErrorMessage = "You must enter a number between 0 and 50,000"
End With
End Sub
I got the same error message. So, I wish to know in what context I am supposed to use validation.
Thanks.