QP School

Full Version: User forms in VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Description:

UserForms are custom forms you can create to interact with users.

1. Input Box

InputBox allows you to prompt the user for input.

Example:

Sub ExampleInputBox()
    Dim userInput As String
    userInput = InputBox("Please enter your name:")
    MsgBox "Hello, " & userInput & "!"
End Sub

2. Buttons

You can add buttons to UserForms and assign code to run when the button is clicked.

Example:

Private Sub btnOK_Click()
    MsgBox "You clicked the OK button!"
End Sub

3. Dropdowns

Dropdowns (ComboBoxes) allow users to choose from a list of options.

Example:

Private Sub cboFruit_Change()
    MsgBox "You selected: " & cboFruit.Value
End Sub