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

creating drop down box

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

ResolvedVersion 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:

Adding date and time

Here are two quick ways to add the date and time to your spreadsheet:

1) Type =NOW(), which displays both date and time in the same cell
or
2) Hold Ctrl and type the colon (:) into one cell for the date and the semi-colon(;)into another for the time.

Note that =NOW() updates to the current date/time whenever the spreadsheet recalculates.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.