QP School
Creating an input box to ask a user for its name in VBA - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Creating an input box to ask a user for its name in VBA (/showthread.php?tid=5237)



Creating an input box to ask a user for its name in VBA - Qomplainerz - 07-27-2023

Description:

This code prompts the user to enter their name using an input box and then displays a personalized greeting.

Example:

Sub PersonalizedGreeting()
    Dim userName As String

    userName = InputBox("Please enter your name:")
    If userName <> "" Then
        MsgBox "Hello, " & userName & "! Welcome to Excel VBA."
    Else
        MsgBox "You did not enter a name. Goodbye!"
    End If
End Sub

Explanation:

This code defines a subroutine named PersonalizedGreeting. 
It declares a variable userName to store the user's input. 
The InputBox function displays a prompt asking the user to enter their name. 
If the user provides a name, a personalized greeting is shown in a message box. 
If the user leaves the input box empty, a different message is displayed.

The InputBox function is used to prompt the user for input. 
The If statement checks whether the userName variable contains a value. 
If it does, the personalized greeting is shown; otherwise, a message indicating that no name was entered is displayed.