How to add validation by VBA

  • Thread starter Thread starter michelle_ho
  • Start date Start date
M

michelle_ho

I want to set validation of a cell from a list of value in another exce
file. I know that I can do from Data Menu -> Validation. However,
want to do it by writing VBA code.

Example:
In A.xls, cell A1 = Apple
cell A2 = Orange
cell A3 = Pear
cell A4 = Banana

Then in B.xls, I want to set cell D3 can have the value only from th
above list,

How can I do so?

Thx a lot
 
You cannot do this directly since datavalidation does not accept it.
HOWEVER, you can name the range in the active workbook that refers to the
range in the source workbook.
insert>name>define>name it mylist>in the refers to box type in
'=[20010112.xls]Data!$A$14:$A$19
now in the data validation cell use LIST and type in =mylist
voila!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top