How to mention a range of validation list in VBA?

N

norika

Dear all experts,

I create a named validation list called "chuen_PN" via marco recording on
worksheet1 with the similar code like following:
.......
Range("A1:C12").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=
_
xlBetween, Formula1:="=chuen_PN"
.IgnoreBlank = True
.InCellDropdown = True
......
......
......

Remark * ( soruce of chuen_PN is in different worksheet of the same workbook
..)

Now I want to use VBA code to point the range instead of the named
(chuen_PN) , but it's failed when I change the code like following..

......
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="worksheet(index).range("A1:A12")"
.IgnoreBlank = True
.InCellDropdown = True
......

Can I define a range by VBA code (worksheet(index).range......) in
validation list here?

Thanks all
 
K

keepITcool

Norika,
it's not a programming problem:

data validation does not allow a range on a different worksheet.
you MUST go via a defined name aka "named range".

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


norika wrote :
 
B

Bob Phillips

If the DV is pointing to another worksheet, you have to use a name to
reference through. If it is not, you don't need the worksheet name.
 

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

Top