InputBox
Prompts the user for a single text value.
value = InputBox(prompt, title, default)This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Prompts the user for a single text value.
InputBox is a quick way to collect one value during macro execution, such as a sheet name, reporting month, or lookup code. It is acceptable for lightweight prompts, but fragile for validated numeric workflows where a user form would be safer.
Quick reference
Syntax
value = InputBox(prompt, title, default)
Inputs
Parameters
See it in practice
Examples
Prompt for a target worksheet
Dim targetSheet As String
targetSheet = InputBox("Enter the worksheet name to export", "Export target", "Sheet1")
If Len(targetSheet) > 0 Then
Worksheets(targetSheet).Activate
End IfAlways validate the returned text before using it as a workbook reference.
Debug faster
Common Errors
Run-time error
Cause: Assuming the entered text is valid and using it directly as a sheet, range, or number.
Fix: Check for an empty string, validate the value, and guard the downstream object lookup.
Runtime support
Compatibility
Common questions
Frequently Asked Questions
Prompts the user for a single text value.
prompt: Question shown in the dialog. title: Optional dialog title. default: Optional prefilled value.
Run-time error: Check for an empty string, validate the value, and guard the downstream object lookup.