Monday, June 18, 2012

How Can I Make a Dynamic Drop


1. Launch Excel 2003 and click the Tools menu. Select Macro and then Visual Basic Editor. Insert a new module by clicking the Insert menu and selecting Module. Type the following to create a new procedure:Private Sub createDropDownList()On Error GoTo Err_createDropDownList:
2. Type the following to dynamically create a new ComboBox control in the active Excel worksheet:With ActiveSheet.OLEObjects.Add(ClassType:='Forms.ComboBox.1', Link:=False, _DisplayAsIcon:=False, Left:=70, Top:=60, _Width:=100, Height:=25)With .Object.AddItem 'Item List 1'.AddItem 'Item List 2'.AddItem 'Item List 3'End WithEnd WithThis code will also add three items to the ComboBox control.
3. Type the following to exit the procedure and handle errors:Exit_createDropDownList:Exit SubErr_createDropDownList:MsgBox Err.DescriptionResume Exit_createDropDownList:End Sub
4. Press 'F5' to run your procedure. You will see a new ComboBox control created in your worksheet.

Blogger news