» Change the value/content of several UserForm-controls using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - User Forms, Input boxes in VBA
VERSION - All Microsoft Excel Versions
looping through the controls in the collection, e.g. like this: For Each cb In dlg.CheckBoxes.
In Excel 97 or later the UserForm-object doesn't group the controls in the same way.
Below you will find some example macros that shows how
you can change the value/content of several UserForm-controls:
Sub ResetAllCheckBoxesInUserForm()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
End If
Next ctrl
End Sub
Sub ResetAllOptionButtonsInUserForm()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
End If
Next ctrl
End Sub
Sub ResetAllTextBoxesInUserForm()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then
ctrl.Text = ""
End If
Next ctrl
End Sub
Book Store:
Recommended Books:
- VBA for Modelers: Developing Decision Support Systems Using Microsoft« Excel
- Keys to Reading an Annual Report (Barron's Business Keys)
- Microsoft Access Version 2002 Step by Step
- Special Edition Using Microsoft Office XP
- Treason: Liberal Treachery from the Cold War to the War on Terrorism
- Accounting the Easy Way
No comments have been submitted.

