Microsoft Office Tutorials and References
In Depth Information
This example has two additional procedures that control whether the Remove button is enabled
or disabled. These events are triggered when the ListBox is entered (either via a keystroke or a
mouse click). The net effect is that the Remove button is enabled only when the user is working
in ListBox2 .
Private Sub ListBox1_Enter()
RemoveButton.Enabled = False
Private Sub ListBox2_Enter()
RemoveButton.Enabled = True
This example, named listbox item transfer.xlsm , is available on the companion
Moving items in a ListBox
Often, the order of items in a list is important. The example in this section demonstrates how to
allow the user to move items up or down in a ListBox. The VBE uses this type of technique to let
you control the tab order of the items in a UserForm. (Right-click a UserForm and choose Tab
Order from the shortcut menu.)
Figure 14-13 shows a dialog box that contains a ListBox and two CommandButtons. Clicking the
Move Up button moves the selected item up in the ListBox; clicking the Move Down button
moves the selected item down.
This example, named listbox move items.xlsm , is available on the companion
Figure 14-13: The buttons allow the user to move items up or down in the ListBox.