Sky walker
Have you tried putting the options in a range of XL cells and directing the validation to the range?
Main Topics
Browse All TopicsDear experts,
I need to add a validation dropdown list to a cell, I tried using the following code and it works fine
sOptions = "a,b,c,d"
With sheet1.range("E3").Validat
.Delete
.Add Type:=xlValidateList, Formula1:=sOptions
.InCellDropdown = True
.IgnoreBlank = True
End With
However, if I change sOptions to
sOptions = "Customer Name,Customer Number,Address 1"
I hit the following error:
"Run-time error '-2147417848 (80010108)': Method 'Add' or object 'Validation' failed"
I'm not sure why it happened but suspect the spaces in the string. I tried
sOptions = "'Customer Name','Customer Number','Address 1'"
but didn't work too. What else can I do? Please help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yes, you can put the list on another sheet. Even another workbook. But you may need to name the range on your home sheet and then refer to it by name in the validation dialog or VBA call. So, if you define the name "valrange" in book1 as
=[Book2]sheet1!$a$1:$A$5
which I would do by pointing, not typing, you can set validation in book 1 to
=valrange
and the list will be pulled from the address in the named range.
Dear remarkl,
Are you sure we can reference other worksheets for validation? I hit error doing that. In fact, if I set the validation rules in Excel (not VBA) from the menu Data - validation, it won't let me move to other worksheets. If I force an address referencing other worksheets I get an error saying:
"You may not use references to other worksheets or workbooks for Data Validation criteria."
Oh, ye of little faith.
Open two workbooks.
In book1 sheet1 a1:a5, put entries
In book 2 define the name "valrange" by pointing to A1:A5 on book1 sheet1
In book 2, pick a cell and set its validation to a list with the reference
=valrange.
Go ahead. Humor me.
Or, I can send you the workbooks, as they are open on my machine.
LJK
P.S. I have not tried to do this in VBA.
Thank you very much remarkl, I haven't used name before. Excellent.
However, I had problem setting the value of the name right with these codes:
ActiveWorkbook.Names.Add Name:="valRange", RefersToR1C1:="=Sheet2!A1:
ActiveWorkbook.Names.Add Name:="valRange", RefersToR1C1:="=Sheet2!$A$
Keep error when adding the validation list.
Anyway, I've changed the code a little to the following and it works beautifully.
Sheet2.Range("A1:A7").Name
Great. Thanks!!!
ActiveWorkbook.Names.Add Name:="valRange", RefersTo="=Sheet2!$A$1:$A$
would have worked, I think. the R1C1 form is for when you use R1C1 notation for cells. I'm not sure of the correct syntax, something like
ActiveWorkbook.Names.Add Name:="valRange", RefersToR1C1:="=Sheet2!$R1
I'm actually surprised that the syntax you used works. Thanks for the tip!
Business Accounts
Answer for Membership
by: SkyWalkerPosted on 2004-02-04 at 23:43:24ID: 10278509
I'm sorry, I've forgotten to mention that everytime after hitting the problem, I'll get the following message when I try to close excel.
"Cannot quit Microsoft Excel"