VBA Inserted Data Validation Fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use Dynamic Data Validation inserted at run time but it fails
consistantly with : Method 'Add' of Object 'Validation' failed.

The most basic snippet I tried was:
-------------------------------------------
---sub cmdClick()

Dim wks As Worksheet

Set wks = Worksheets("sheet1")

wks.Range("A1").Validation.Add xlValidateList, , , "=1,2,3"


The parent sheet is full of ADO 2.8 and other code that is fine. It is only
this functionality that fails.

Is there some other property to set or enable? I cannot find anywhere
speicifying any other object requirements.

Any help on this will be greatly appreciated.
 
RickK

Two things:

Get rid of the equal sign in your list.
Also, if you run this more than once, you need to delete the validation,
before you can add it:

With wks.Range("a1").Validation
.Delete
.Add xlValidateList, , , "1,2,3"
End With

hth,

Doug
 
RickK,

It works for me and I can't think of what the issue might be.

Doug
 
The sheet isn't protected, is it? That would get you the error.

Doug
 

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