0

I've looked online for an hour and can't find any solution that has worked for me. I have a range of cells which I want to apply data validation to each cell in that range based on another range. I am not sure if I need a For Each loop or if I can just assign the validation to the whole list at one time. Here is what I have so far:

With Range(rngMonthStart, rngMonthEnd)
    With .Validation
         .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:= ("='Settings'!" & totalrange.Address)
    End With
End With

When it gets to the .Add line I get an Application Defined Error. Any help is super appreciated

user692942
  • 16,398
  • 7
  • 76
  • 175
SanomaJean
  • 181
  • 1
  • 2
  • 14

2 Answers2

4

You seem to be overwriting the validation. If it already exists, overwriting leads to runtime error. Try:

With .Validation
    .Delete  
    .Add ...
A.S.H
  • 29,101
  • 5
  • 23
  • 50
0

In case you have done the .Delete, and it still fail at .Add with "Application Defined Error". Please check if the worksheet is protected or not. It should run fine once the worksheet is unprotected.

bkyee
  • 74
  • 5