557 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Advanced controls in userforms with VBA macros Part five of a nine-part series of blogs |
---|
The two previous parts of this mini-blog have shown how to draw forms and how to write code to handle form events. This final part shows how to add some of the more exotic controls to user forms, like combo boxes, list boxes, multipage controls, spinners and option buttons.
This blog is part of our Excel VBA tutorial. Wise Owl's main business is running Excel, VBA and other courses for businesses.
|
The previous two parts of this blog have considered general features for combo and list boxes, but there is one thing you can do with a listbox that you can't do with a combo box: allow a user to select lots of records at the same time.
This is the easy part! Just change the properties of the listbox as follows:
You can choose 3 possible values for a MultiSelect listbox. The difference between frmMultiSelectMulti and frmMultiSelectExtended (who thinks up these names?) is that with the latter you can click and drag to select lots of adjacent items at the same time.
You can then click on any item to select (or deselect) it:
Here we have selected at least 3 departments (more may be shown selected if we scroll down).
You can loop over the items in the Selected array to find out which items were chosen:
Private Sub btnOrder_Click()
Dim EachDepartment As Long
'loop over all of the items in the list
For EachDepartment = 1 To Me.lstDepartment.ListCount
'for each item, see if it was selected
If Me.lstDepartment.Selected(EachDepartment - 1) = True Then
'do something with it!
Debug.Print Me.lstDepartment.List(EachDepartment - 1)
End If
Next EachDepartment
End Sub
Notice here that the ListCount property gives the number of items in the list (numbered from 1), but the Selected array is numbered from 0.
Parts of this blog |
---|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.