I am trying to set data validation for a range of cells using VBA. I get error 1004 at runtime (so useful) "A specific application or object error" with this code.
With rngRangeToCheck.Cells(lrownum, 1).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=choice .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With
In Formula1, selection is a variable passed to a function that resembles "= SomeNamedRange" from the workbook in which the code is located.
Error in .Add code section.
If I hard code Formula1 as Formula1:="=SomeNamedRange" , it works without problems. I really didnโt want to hard code it, because I am doing it with a lot of possible values โโfor the โchoiceโ, and that would be just less than pure code, I think.
I have been collecting Google and about 3 different books for several days trying to figure this out.
Any suggestions? Thanks for helping the newbie.
source share