View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default Runtime error 1004

You might have to add a .Delete method to your code, to insure that
there is not already data validation in that cell, for some reason.

With Worksheets(1).Range("N4").Validation
.Delete
.Add Type:=xlValidateWholeNumber, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="1", _
Formula2:="8"
.ErrorMessage = "Enter digit between 1 and 8"
.ShowInput = False
.ShowError = True
End With

When I ran your macro more than once, then I got the same error
("Run-time error '1004': Application-defined or object-defined error").

Data validation is not totally foolproof. In Excel 2000, you can cut and
"paste special value" a value outside your range, and the data
validation error message will not be displayed. I also think it is
generally a good idea to include an Input message as well as an Error
message, so that the user knows that the cell has data validation in it.
--
Regards,
Bill Renaud