How to create drop-down list using VBA in Excel '07

traxmax

New Member
Joined
Oct 20, 2014
Messages
2
Can someone please help me to create a drop-down list using VBA in Excel 2007?

I want to have a drop-down list of values (7 in total, 2 words each).
Once the particular value is selected the macro writes a value category (3 categories, 2 words each) into a specific cell as well as the value short description (15 words max) into an other cell (same page).

I don't want those drop-down values to be in any worksheet or pulling from any other source.
Please help. Thank you!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello and welcome to the Board

See if this is useful:

Code:
' standard module
Sub Create_DropDown()
Dim Ctrl As OLEObject
With ActiveSheet
    Set Ctrl = .OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
    DisplayAsIcon:=False, Left:=160, Top:=80, Width:=90, Height:=20)
End With
With Ctrl.Object
    .AddItem "Jackie Stewart"
    .AddItem "Gerard Ducarouge"
    .AddItem "Jochen Rindt"
    .AddItem "Ronnie Peterson"
    .AddItem "James Hunt"
    .AddItem "Colin Chapman"
    .AddItem "Niki Lauda"
End With
Ctrl.Name = "box1"
End Sub

Code:
' at sheet module
Private Sub box1_Change()


Dim cats, ci, desc
cats = Array("driver", "designer", "owner") ' categories
ci = Array(0, 1, 0, 0, 0, 2, 0)
desc = Array("desc0", "desc1", "desc2", "desc3", "desc4", "desc5", "desc6") 'descriptions
Me.Cells(10, 4) = cats(ci(Me.box1.ListIndex))
Me.Cells(11, 4) = desc(Me.box1.ListIndex)


End Sub
 
Upvote 0
Hello and welcome to the Board

See if this is useful:

Code:
' standard module
Sub Create_DropDown()
Dim Ctrl As OLEObject
With ActiveSheet
    Set Ctrl = .OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
    DisplayAsIcon:=False, Left:=160, Top:=80, Width:=90, Height:=20)
End With
With Ctrl.Object
    .AddItem "Jackie Stewart"
    .AddItem "Gerard Ducarouge"
    .AddItem "Jochen Rindt"
    .AddItem "Ronnie Peterson"
    .AddItem "James Hunt"
    .AddItem "Colin Chapman"
    .AddItem "Niki Lauda"
End With
Ctrl.Name = "box1"
End Sub

Code:
' at sheet module
Private Sub box1_Change()


Dim cats, ci, desc
cats = Array("driver", "designer", "owner") ' categories
ci = Array(0, 1, 0, 0, 0, 2, 0)
desc = Array("desc0", "desc1", "desc2", "desc3", "desc4", "desc5", "desc6") 'descriptions
Me.Cells(10, 4) = cats(ci(Me.box1.ListIndex))
Me.Cells(11, 4) = desc(Me.box1.ListIndex)


End Sub

Thank you so much, Worf for your help and insight into my question.The code is nice as well as your sense of humor - five drivers who seems to motor the designer days and nights ... lol :rofl:
I very much appreciate and enjoy both aspects of your quick response :) Thank you again!!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top