I’m trying to set list validation for a cell based on the contents of another cell, using a named range that matches the contents of a cell on my data entry sheet to a range on the Validation sheet (see this SO question). The named range’s formula is:
=OFFSET(validation!$B$1,MATCH(INDIRECT(ADDRESS(CELL("row"),CELL("col")-2)),validation!$A:$A,0)-1,0,COUNTIF(validation!$A:$A,INDIRECT(ADDRESS(CELL("row"),CELL("col")-2))),1)
The problem is that if the cell referred to by ADDRESS(CELL("row"),CELL("col")-2) is empty, setting the validation with VBA using Range.Validation.Add gives an error:
Application-defined or object-defined error
and then it doesn’t add the validation to the cell. Is there any kind of error handling I can do on the Validation.Add call to make sure the validation gets set? Or a way to modify the named range formula so that it outputs a value even if the contents of ADDRESS(CELL("row"),CELL("col")-2) don’t return a match on the validation sheet?
As a work around try this:
ValListnamed range to refer to a simple range.A bit clunky, but it seems to work.