creating drop down box

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Creating Drop Down Box in Combo Box

Creating Drop Down Box in Combo Box

resolvedResolved · Medium Priority · Version 2007

Sugi has attended:
Excel VBA Intro Intermediate course

Creating Drop Down Box in Combo Box

When creating a drop down box in a combo box, can you do it without creating a List Page and instead from the data sheet?

RE: Creating Drop Down Box in Combo Box

Hi Sugi

Thanks for your question

The procedure outlined below, writes unique values to an array from a specified column. You can then use the additem method of the combo box to add each item in the array to the combo box

Sub GetUniqueItems

Dim UniqueList() As String
Dim strCurrentItem As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim blnExists As Boolean

ReDim UniqueList(1)

blnExists = False

UniqueList(1) = Range("A1").Value
k = 2

For i = 2 To Range("A1").CurrentRegion.Rows.Count
blnExists = False
strCurrentItem = Range("a1").Cells(i, 1)
For j = 1 To UBound(UniqueList)
If UniqueList(j) = strCurrentItem Then
blnExists = True
Exit For
End If
Next j
If blnExists = False Then
ReDim Preserve UniqueList(k)
UniqueList(j) = strCurrentItem
blnExists = False
k = k + 1
End If
Next i

For j = 1 To UBound(UniqueList)
Debug.Print UniqueList(j)
Next j

End Sub

Fri 24 Dec 2010: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Shared Conditional Formatting

In a shared workbook, conditional formats applied before the workbook was shared will continue to work; however you cannot modify the existing conditional formats or apply new ones.

View all Excel hints and tips


Server loaded in 0.08 secs.