Learn about VBA Input box
In VBA, an InputBox function allows you to prompt the user for input. This is particularly useful for getting values directly from users without needing to create a form. Here’s how you can use it:
Basic Syntax of InputBox
Dim userInput As String
userInput = InputBox(Prompt, Title, Default)
- Prompt: The message displayed in the input box.
- Title: The title of the input box window (optional).
- Default: A default value that appears in the input field (optional).
Example 1: Simple Input Box
Sub simpleinputbox() Dim userName As String userName = InputBox("Please Enter Your Name: ", "User Name") If userName <> "" Then MsgBox "Hello, " & userName & "!" Else MsgBox "No Name Entered!" End If End Sub
Example 2: Using a Default Value
Sub inputboxwithdefault() Dim age As String age = InputBox("Please enter your age", "User age", "25") If age <> "" Then MsgBox "You are " & age & " Years Old" Else MsgBox "No entered a Value" End If End Sub
Example : get a user to
Example 3: Numeric Input and Validation
If you want to validate that the input is a number, you can use IsNumeric:
Example 4: Input Box with a Loop Until Valid Input
You can also loop until the user provides a valid input or cancels.
confirm a decision by typing “Yes” or “No” using an InputBox?
Use an InputBox to get user confirmation and check their input.
For better understanding we should read below article also.
in dept understanding we can go for below link