I am trying to add data validation to a set of cells based on a range of cells from another worksheet. Problem is that the range of cells in the other worksheet is not static and can change.
Overall I am looking for a set of dropdown boxes in the A10:A29 cells with the ingredients in them
When I use =INDIRECT("Ingredients!A2:A320) just using the excel validation wizard it works but I need the end cell to be dynamic.
I have this current vba code
Dim endrow As Integer
endrow = Sheets("Ingredients").Range("A" & Rows.Count).End(xlUp).Row
Range("A10:A29").Select
With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=INDIRECT(" & Chr(34) & "Ingredients!A2:A" & endrow & Chr(34) & ")"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
I get a 1004 error on this code.
To make it easier for anyone looking at this the end result I am aiming for in the formula section is this:
=INDIRECT("Ingredients!A2:A*endrow*)
Integer
: it fails after row 32,767.. And Using theSelection
object is probably not a good idea in most cases (including this one). See stackoverflow.com/questions/10714251/… – Ioannis