Runtime Filling of Combo in Validation


Posted by Anand on March 01, 2001 1:56 AM

Hi All,

I need to fill the Validation dropdown at runtime.
The Range of Values ( Size and values) is Dynamic and
Picked from another part of the Sheet.
How can I do this Programmatically .

Thanking you in advance

Posted by Aladin Akyurek on March 01, 2001 2:49 AM

If I understood it right, you need to create a dynamic named range. The name so defined must then be entered as the source for your dropdown list.

Suppose you have the values in F from F1 on, which you want to show up in a dropdown list. It's required that no other values/formulas appear in column F.

Activate the option Insert|Name|Define, enter DynList as name for Names in workbook and

=OFFSET(x!$F$1,0,0,COUNTA(x!$F:$F),1),

where x is the name of the sheet where the values are.

Activate the option Data|Validation, choose List for Allow on Settings tab and enter =DynList for Source.

After these steps, you can add/remove values to column F on sheet x at will.

Aladin

Posted by David Hawley on March 01, 2001 3:03 AM

Hi Anand

Here is how you would do it at Run time.

Sub TryThis()
Dim MyList1 As Range

Set MyList1 = Range("A65536").End(xlUp)
Set MyList1 = Range("A1", MyList1.Address)

With Range("B1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & MyList1.Address
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub


Just substitute the ranges to suit.


Dave

OzGrid Business Applications

Posted by anand on March 01, 2001 5:18 AM

Hi Dave & Aladin ,

Thanks a lot for your responses , I have a feeling theyll work but i am trying it out only tomorrow .. Daves soln seems to be like passing the parmeters that the wizard asks when using validation . Aldins soln seems to be done at design time.. and i have to try it out. Anyways I am sure one of them will work.. Thanks a lot for your time .

Regards

Anand



Posted by anand.vaidyanathan@citicorp.com on March 01, 2001 5:46 AM

Hi Aladin,

Your Solution was great cos I had no idea of doing this and like a genie you sorted this with no code at all .. i tried it and it works.. Thanks a lot.

cheers

Anand