Dropd Down (validation: list) on the fly with a code - a problem

A

AB

Hi,

I was hoping if anyone could help me - i'm trying to write a code that
would create a dropdown in a cell on the fly. That's the simple code:

With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="1;2"
.InCellDropdown = True
End With

So far so good, but the problem is that i want the dropdown to let the
user enter either 1 or 2 but if i run the above code then the dropdown
lets the user enter only one value = "1;2".
In the meantime if i enter the same list ("1;2") manualy into the
validation (Data>validation - i.e., don't do it with a code) - then
everything is fine - i.e., the dropdown offers either value ("1" or
"2") and not the combined ("1;2").

The point is that i'll need to define the dropdown lists on the fly
and they'll constantly change, that's why i wanted to do that with a
code.

Any help would be greatly appreciated.
Thanks!
 
P

papou

Hi AB
Use the comma separator instead, eg:
xlBetween, Formula1:="1,2"

HTh
Cordially
Pascal
 
A

AB

It was so simple...!!
Perfect! THANKS!

I must start using "," as list seperators in my Regional settings, i
believe - otherwise i'll have confusions like this all the time...

Thanks again.
 
P

papou

AB
I must start using "," as list seperators in my Regional settings, i
believe

There is no need for this, I have a semi-colon as list seperator in my
settings.
Just remember VBA has the US settings by design.

HTH
Cordially
Pascal
 

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