Web.cecs.pdx.edu



Third VBA program in Excel (use of RadioButtons, Frames, and ComboBoxes)Radio buttons return a Boolean. Their value is True if selected or False if not selected. If several RadioButtons are placed in a Frame (from toolbox), then only one will be allowed to be selected by the user. For example, use the RadioButton to select the problem units.Add two RadioButtons. For one use “Inches” for caption and for the other “mm” for caption. Set the initial value of the button for inches to True and the other to False.Place both option buttons is a frame (from the toolbox). Use the caption “Select Units” for the frame.Add two textboxes. For one the caption is “Units Selected” and leave the other blank.Add a command button “Calculate” as before.Add the following for the code for CommandButton:Dim Units As StringIf OptionButton1 = True Then Units = "Inches"ElseIf OptionButton2 = True Then Units = "mm"End IfWrite the results in the blank Textbox (example: Textbox2)Textbox2.value = UnitsAdd a module to “ThisWorkbook” and add a Sub to this module. Call it MyTest:Sub MyTest()Test the macro and see what happens when you select different buttons.Add a ComboBox from the toolbox. A ComboBox allows selection from a drop down list of options. In this problem, we select from a list of colors.To add the choice items to a ComboBox we can use a special Sub called UserForm_Initialize() in the userform code for UserForm1as shown below: Sub UserForm_Initialize() ComboBox1.AddItem "Red" ComboBox1.AddItem "Blue" ComboBox1.AddItem "Yellow" ComboBox1.AddItem "Green" ComboBox1.AddItem "Brown"End Sub To add the value of the selected item from ComboBox, use the following code for the Calculate CommandButton:Color = ComboBox1.ValueTextBox3.Value = Color ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download