18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Part VI<br />

Programming Excel with VBA<br />

ComboBox control<br />

A ComboBox control is similar to a ListBox control. A ComboBox, however, is a drop-down box, and it<br />

displays only one item at a time. Another difference is that the user may be allowed to enter a value that<br />

does not appear in the list of items.<br />

Figure 42.5 shows a ComboBox control that uses the range D1:D12 for the ListFillRange and cell A1 for the<br />

LinkedCell.<br />

FIGURE 42.5<br />

A ComboBox control.<br />

The following is a description of the most useful properties of a ComboBox control:<br />

n<br />

n<br />

n<br />

n<br />

n<br />

n<br />

n<br />

BoundColumn: If the ListFillRange contains multiple columns, this property determines which<br />

column contains the returned value.<br />

ColumnCount: The number of columns in the list.<br />

LinkedCell: The worksheet cell that displays the selected item.<br />

ListFillRange: The worksheet range that contains the list items.<br />

ListRows: The number of items to display when the list drops down.<br />

ListStyle: Determines the appearance of the list items.<br />

Style: Determines whether the control acts like a drop-down list or a ComboBox. A drop-down<br />

list doesn’t allow the user to enter a new value.<br />

CommandButton control<br />

A CommandButton is most commonly used to execute a macro. When a CommandButton is clicked, it<br />

executes a macro with a name that is made up of the CommandButton’s name, an underscore, and the<br />

word Click. For example, if a CommandButton is named MyButton, clicking it executes the macro<br />

named MyButton_Click. This macro is stored in the code module for the sheet that contains the<br />

CommandButton.<br />

740

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!