I’d like to select all cells (except the first one) from column A of Sheet2 that are not empty, and use it as the list for data validation on a range of Sheet1. I already have code to add the validation:
Cells.SpecialCells(xlCellTypeFormulas).Offset(0, 1).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=**The range i need**"
.IgnoreBlank = True
.InCellDropdown = True
End With
I’m not able to make it work in Excel 2003; in Excel 2003 it’s not possible to add a reference to another sheet for data validation.
If you want to have your validation list cross worksheets, you need to define a named range for the validation data. In Excel 2003 (if I recall correctly) you define name ranges in the Insert > Named ranges > Define. If you want to assign the validation in code you just use the name of your range as the address.
Of course you probably won’t have to do this in code – you’ll only have to define the validation rule once, then update the named range from that point on. To update the named range to refer to non-blank cells on a particular worksheet, you can use something like this.