Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create dropdown list in VBA

Status
Not open for further replies.

JA3395

Programmer
May 22, 2007
88
IE
Does anyone know if it is possible to generate a dynamic dropdown-list in a cell by calling a VBA function passing the contents of another cell

Something along the lines of:-

Code:
=GenerateList(C4)

Code:
Function GenerateList(Byval strClass As String) As [DropDownList]

Dim lbxDropDownList As DropDownList

     Select Case strClass
     Case "A"
          lbxDropDownList.Add "X"
     Case "B"
          lbxDropDownList.Add "Y"
     Case "C"
          lbxDropDownList.Add "Z"
     End Select

     set GenerateList = lbxDropDownList 

End Function

I haven't yet found a Reference that will give me an object something like {DropDownList} do I have to use a Collection and manipulate that?

Thanks in anticipation [love]

J.
[ponder]
 



Hi,

You don't need code for dynamic list named ranges. You might also check out the Data>Validation - LIST feature.

The key element is using a Named Range in the ListFillRange of ControlSource.

How can I rename a table as it changes size faq68-1331

Skip,

[glasses] [red][/red]
[tongue]
 
I've tried that solution, but it only works when the dynamic table is on the same sheet as the list.

The structure I have is that my data is on a hidden sheet (2 tables) and when an item is selected from the first table I want the relevant items from the second table to be selectable.

Now, I also want this dropdown list to be repeatable on all rows in a sheet.

This is why I want to generate the 2 lists in VBA so that each row

=GenerateList1()
=GenerateList2(A1)

I had fun yesterday reproducing an object version of a list, but this is not repeatable.

J.
 



"...when the dynamic table is on the same sheet as the list..."

au contre! Not if you use a Dynamic Named Range. Your range can be on anther sheet.

"...I also want this dropdown list to be repeatable on all rows in a sheet...?

For Data>Validation, copy the FORMAT to any other cell.


Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top