The standard VBA InputBox is limited to about 255 characters of entered text, so it is not suitable for collecting long comments or paragraphs. For longer responses in Excel for Microsoft 365 on Windows, use a UserForm with a TextBox control; also distinguish this input limit from the separate limit on the prompt shown to the user.
The practical limit for entered text
In everyday VBA use, treat the built-in InputBox as a short-response dialog with a practical limit of 255 characters. That is enough for a name, code, brief note, or one-line search term, but not for a long description. If a person needs to paste a paragraph, the dialog may not accept all of it or may return a shortened result. Do not design a process that depends on the built-in box accepting more than its practical limit.
The exact behavior at the boundary can depend on which input-box API and host application you are using, and documentation may describe prompt limits separately from entered-text behavior. If your workflow needs an exact maximum, test the particular dialog in the supported Office version and enforce your own limit in the code. For reliable long-text collection, use a form control rather than trying to work around the standard dialog.
Which VBA input box are you using?
VBA projects commonly use two different dialogs that are both called input boxes. The first is the VBA InputBox function. It returns text as a String and is available in Excel VBA and other VBA hosts. The second is Excel’s Application.InputBox method. It can return different kinds of values depending on its Type argument, such as a number, a range, or text.
For collecting ordinary text, the two are not a way to obtain an unlimited response. Excel’s method is useful when you want a typed value or a selected range, but it is still a small dialog intended for a short answer. Choosing Application.InputBox instead of the VBA function does not turn the dialog into a long-text editor.
- Use
InputBoxfor a quick, short text prompt. - Use
Application.InputBoxwhen Excel-specific input types, such as a range selection, are useful. - Use a UserForm TextBox when users need to enter or paste longer text, see multiple lines, or receive more guidance.
Prompt length is not the same as answer length
The prompt is the instruction displayed above the entry field; the answer is what the user types. These are separate limits and are often confused in discussions of the character limit. Microsoft documents a maximum prompt length of approximately 1,024 characters for the VBA InputBox function, with the visible fit also affected by character widths and the dialog. Excel’s Application.InputBox has its own documented prompt limit of 255 characters. Neither prompt limit means that the user can enter that many characters as a response.
Even where a prompt’s technical maximum is relatively high, a very long instruction is poor dialog design. Users may not see all of it comfortably, and the input box is not a good place for detailed help. Keep the prompt concise, put longer instructions in a worksheet or UserForm, and use a clear title to identify what information is needed.
What happens when the user types too much?
A short input box gives users little room to judge how much text is appropriate. Depending on the API and host, excess text can be refused or the returned value can be shorter than the text the person intended to submit. This is why code should not assume that a response is complete just because the dialog closed. Where completeness matters, tell users the allowed size and validate the returned string.
Also remember that the standard VBA function returns an empty string both when the user clicks Cancel and when the user submits a blank answer. If those actions must mean different things, the function alone does not provide an unambiguous distinction. Excel’s Application.InputBox returns Boolean False when cancelled; when using it for text with Type:=2, inspect the returned Variant’s type so a cancellation can be distinguished from text that happens to look like “False.”
Handling a short response safely
For a short field, check the result before using it. The following Excel VBA example trims leading and trailing spaces and rejects an empty answer. It also makes the cancel limitation explicit: with the VBA function, Cancel and submitting a blank response both produce an empty string.
Sub AskForShortNote()
Dim response As String
' Save a copy of the workbook before running a macro.
' Macros cannot be undone with Ctrl+Z.
response = VBA.InputBox("Enter a brief note (up to about 255 characters):", _
"Short note")
response = Trim$(response)
If Len(response) = 0 Then
MsgBox "No note was entered, or the dialog was cancelled."
Exit Sub
End If
If Len(response) > 255 Then
MsgBox "Please shorten the note to 255 characters or fewer."
Exit Sub
End If
MsgBox "Accepted " & Len(response) & " characters."
End Sub
The length check is a useful safeguard if the input reaches this code from another source or the implementation changes. It cannot restore text that was never returned by the dialog, so it is not a substitute for selecting a suitable control. The sample does not write to a worksheet; add that separately if needed, and check that the destination can hold the complete value.
Collecting longer text with a UserForm
For longer answers in Excel VBA, create a UserForm and add a TextBox control. Set the TextBox’s MultiLine property to True so the user can enter multiple lines. Depending on the layout, set EnterKeyBehavior to True so Enter inserts a line break rather than activating a default button. Make the control large enough to review the response, and consider adding a label that states the purpose and any maximum length your process supports.
For a predictable limit, set the TextBox’s MaxLength property or validate Len(TextBoxName.Value) when the user submits the form. A limit of zero for MaxLength means no limit is imposed by that property; it does not mean unlimited storage in every part of the application. The practical capacity still depends on the control, memory, and where the text will ultimately be stored. A worksheet cell, for example, has a maximum of 32,767 characters.
A well-designed form should also include an explicit Submit or OK button and a Cancel button. Keep the submitted text in a variable or pass it to the relevant procedure, and decide how blank input should be handled. If users paste text, test the form with multi-line content and with the maximum size you intend to support. The VBA editor in Excel for Windows can be opened with Alt+F11; on Mac, the VBA editor and shortcut differ, and keyboard shortcuts can depend on the Mac and Excel settings. UserForms and ActiveX-related behavior can also vary by platform, so verify the form on the operating systems you support.
Choose a control based on the job
Pick the input method according to the type and amount of information, not just because one option takes fewer lines of code. A simple prompt is convenient for a quick value, while a UserForm gives users more space and lets you explain rules. For a value that already belongs in a worksheet, a labeled cell with data validation may be clearer than opening a dialog at all.
- Short, one-off answer: use
InputBoxwhen a brief response is enough and Cancel can be treated like blank. - Range, number, or other Excel selection: consider
Application.InputBoxand choose the appropriate type. - Paragraph, pasted text, or several fields: use a UserForm with a multi-line TextBox and validation.
- Information users need to revisit: use clearly labeled worksheet cells, with validation or instructions where appropriate.
Do not confuse the input dialog’s limit with the capacity of a VBA String. A String variable can hold substantially more text than this small dialog is designed to collect. The bottleneck is the user interface, not the fact that the response is stored in a String. Conversely, a larger control does not guarantee that every downstream destination can store the same amount, so check the final worksheet, file, or system as well.
Frequently Asked Questions
Is the VBA InputBox limit 255 characters?
For practical purposes, yes: treat the standard VBA InputBox as a short-response dialog with an approximately 255-character entered-text limit. If the exact boundary is important, test the specific API and Office host and enforce a maximum in your own code.
Does Application.InputBox allow more text?
Do not rely on it for long responses. Excel’s Application.InputBox is useful for selecting or entering typed values, but it is not a long-text editor. Use a UserForm TextBox for longer answers.
Is the 1,024-character limit for the answer or the prompt?
It refers to the approximate maximum prompt length documented for the VBA InputBox function, not the length of the user’s answer. Excel’s Application.InputBox has a separate prompt limit.
Can VBA InputBox accept multiple lines?
The standard dialog is intended for a brief, single-line response, not for editing a multi-line passage. For paragraphs or line breaks, use a UserForm TextBox configured for multiple lines.
How can I tell whether the user clicked Cancel?
The VBA InputBox function returns an empty string for both Cancel and a blank submission, so those cases cannot be distinguished from that return value alone. Excel’s Application.InputBox returns Boolean False on cancellation; check the returned Variant’s type when collecting text.
Related
- Microsoft Excel Corrupt File? How to Repair It
- Microsoft Excel Find Circular References: A Clear Guide
- Microsoft Excel Consolidate Data: A Practical Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Open a Workbook in the Background, HiddenYes. In Excel VBA, open the file with Workbooks.Open, then set each window in the returned workbook’s Windows…
- Microsoft Office Macro Recorder: How It WorksMicrosoft Office has macro recorders in desktop Excel and Word; in Excel for Microsoft 365 on Windows, choose…
- Excel VBA: List All Sheets in a WorkbookTo list every sheet in the workbook that contains your VBA code, loop through its Sheets collection and…
- VBA Copy Paste Mode: How to Clear and Control ItIn Excel VBA, copy/paste mode is Excel’s temporary state after a cell or range has been copied or…
- Excel VBA Visible Worksheet Property: How to Set ItIn Excel VBA, a worksheet’s visibility is controlled by its Visible property. Set it to xlSheetVisible to show…
- VBA Loop Backwards: Syntax, Examples, and Common ErrorsTo loop backwards in VBA, start at the highest value, end at the lowest, and use a negative…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.