Excel VBA Max String Length: Limits and Workarounds

VBA & macros · Updated November 21, 2026

In Excel VBA, a variable-length String can hold roughly 2 billion characters in theory, but available memory and the way VBA represents strings impose a practical limit well before that for many tasks. Excel worksheet cells have a much smaller, firm limit of 32,767 characters each, so a VBA string can be far longer than the text you can store in one cell.

VBA’s String Limit in Practice

VBA’s documented upper bound for a variable-length string is approximately 2 billion characters. Treat that as a language-level ceiling, not as a promise that a macro can safely create a string of that size. A string must occupy memory, and VBA needs memory for other variables, Excel, the workbook, and temporary copies made while the macro runs. A request to allocate an enormous string may therefore fail much earlier with an out-of-memory or “Out of string space” error.

The practical answer to “What is the maximum string length?” is consequently two-part: the theoretical limit is about 2 billion characters, while the usable limit depends on available memory and the operation being performed. A string that fits in memory by itself may still fail when the code duplicates it, appends to it repeatedly, or passes it to another component.

Changing from 32-bit to 64-bit Excel can give Excel access to more address space, but it does not remove VBA’s string representation limits, Excel’s worksheet limits, or the memory needed by the rest of the application. Nor does it mean every macro can allocate a multi-gigabyte string. A large file or a very long string should be tested with realistic data and error handling.

Why the Maximum Is Not a Sensible Target

A string’s contents are only part of its memory cost. VBA strings use Unicode, and their characters are represented using UTF-16 storage. In ordinary cases, this means roughly two bytes per character for the text itself, plus internal bookkeeping and memory-allocation overhead. Some Unicode characters, such as many emoji, use a pair of UTF-16 code units, so their storage and length behavior can differ from a simple “one visible symbol equals one character” assumption.

Memory use can grow further during processing. For example, concatenating a large existing string with a new piece may require VBA to allocate space for the combined result while the original value still exists. Converting the string, assigning it to an object, or creating a second copy can also temporarily raise the peak memory requirement. The amount of free memory is not a single fixed number: it varies with the Excel process, workbook size, add-ins, and other applications.

For large text workloads, it is often better to process data in manageable pieces than to build one giant string. That makes it easier to identify the source of an error, keep memory use predictable, and write results to a file or other storage in stages.

Excel Worksheet Cells Have a Separate Limit

A worksheet cell can contain at most 32,767 characters. That is a worksheet-content limit, not the maximum size of a VBA String. A macro can hold text that is longer than one cell, but assigning all of it to a single cell cannot make that cell accept the full value. If a result exceeds the cell limit, split it across multiple cells, store it in a text file, or use a data format designed for longer content.

Excel also displays only part of a long cell value directly in the grid: the visible amount depends on the cell’s width, formatting, and neighboring cells, and Excel documents a 1,024-character display limit in a cell. This display behavior is not the same as the 32,767-character content limit. A value that appears cut off on the sheet may still have more text available in the Formula Bar or in the cell’s underlying value.

Formula text has its own constraints as well. In current desktop Excel, a formula can contain up to 8,192 characters. This is distinct from the length of a value held in a VBA variable and from the amount of text returned to a cell. When a macro writes a formula, the formula-length limit applies; when it writes a literal text value, the cell-content limit applies.

  • VBA variable: roughly 2 billion characters in theory, subject to memory and implementation limits.
  • Worksheet cell: no more than 32,767 characters of content.
  • Formula: up to 8,192 characters in current desktop Excel.
  • Visible grid display: may show less than the full cell value.

How VBA Measures a String

Use the Len function to find a string’s length. It returns a Long value, which can represent a count up to 2,147,483,647. For standard text, Len is the usual way to check how many characters VBA reports. It does not tell you how many bytes a string occupies; LenB reports the length in bytes for a string representation, which is useful in some low-level or file-format work but is not a substitute for a worksheet cell’s character limit.

For example, a macro can inspect the selected cell’s value and report the count VBA sees:

Sub ReportSelectedCellTextLength()
    Dim textValue As String

    ' Read the active cell's value as text.
    textValue = CStr(ActiveCell.Value2)
    MsgBox "Length reported by Len: " & Len(textValue)
End Sub

This example assumes the active cell contains a value that can be converted to text. It reports VBA’s count; it does not increase the cell’s capacity or reveal how many characters are visible in the grid. If the active cell contains an Excel error value, conversion with CStr can raise an error, so production code should check for errors before converting.

Fixed-Length and Variable-Length Strings

Most Excel VBA code should declare ordinary variable-length strings, such as Dim textValue As String. Their size can change as the value changes, up to the language and memory limits. A fixed-length declaration reserves a specified character count, for example Dim code As String * 12. Fixed-length strings are useful in some legacy formats and interfaces that require fields of a known width, but they are not a way to store larger text. Values assigned to them are padded or constrained to the declared width.

For everyday macro work, a fixed-length string is usually the wrong choice for user-entered text, imported data, or generated output. Prefer a variable-length string unless a file specification or API explicitly requires a fixed-width field. If you are working with a fixed-length field, account for padding when measuring it; its declared width and the meaningful text inside it are not necessarily the same.

Building Large Strings More Efficiently

Repeatedly appending small pieces to a growing string can be inefficient for very large output because each operation may require reallocating and copying data. For modest text, the simple approach is fine. For larger workloads, collect pieces and combine them once, or write output incrementally to a file rather than retaining the entire result in memory.

For example, an array of pieces can be combined with VBA’s built-in Join function. This small example shows the pattern; it does not approach the memory limit:

Sub JoinTextPieces()
    Dim pieces(0 To 2) As String
    Dim combined As String

    ' Store separate pieces before joining them.
    pieces(0) = "North"
    pieces(1) = " "
    pieces(2) = "wind"
    combined = Join(pieces, vbNullString)

    MsgBox combined & " (" & Len(combined) & " characters)"
End Sub

The result is Northwind with a length of 9, because the example puts the space in a separate array element but uses an empty separator; to include the space, use Join(pieces, vbNullString) with a space as the middle piece, as shown. For streaming output, use file-writing methods that write one record or chunk at a time, rather than first making a complete copy in a string. The right approach depends on whether the destination is a cell, a text file, or another application.

Before running any macro, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z, even when a macro appears to make only a small change.

Common Problems and Limits to Check

When code fails with large text, first identify which limit it reached. A string can be valid in memory but too long for the destination cell; a formula can exceed the formula-text limit even when its result is short; or an allocation can fail because the process does not have enough memory. These are different problems and need different fixes.

  • Text is missing after writing to a cell: check whether the value exceeds the 32,767-character cell limit and whether the text is merely hidden by the grid display.
  • A formula assignment fails: count the formula characters and check the formula limit separately from the result’s length.
  • An out-of-memory error occurs: reduce the size of each batch, avoid unnecessary copies, and consider writing or processing the data in chunks.
  • Len reports a surprising count: remember that VBA operates on Unicode text and some visible symbols may use more than one UTF-16 code unit.
  • A macro works on one computer but not another: compare Excel bitness, available memory, workbook size, and add-ins rather than assuming the string itself has a different universal limit.

When the text originates in a worksheet, checking its length before assigning or transforming it can make failures easier to diagnose. When it comes from an external source, validate the input and decide what should happen to overlong records: reject them with a clear message, split them deliberately, or store them outside a cell. Silent truncation is rarely a good data-handling policy.

Windows, Mac, and Excel for the Web

The core VBA string behavior is broadly the same in Excel for Microsoft 365 on Windows and Excel for Mac. The available memory and application environment can differ, but moving a workbook to a Mac does not remove worksheet cell limits or make a string unlimited. Excel for the web can open macro-enabled workbooks, but it does not run VBA macros; use desktop Excel to execute VBA code.

For users handling very large text, the important distinction is usually not Windows versus Mac but whether the text must live in a worksheet cell and whether the macro needs to hold the whole dataset in memory. A desktop version with more available memory may help with some workloads, but it cannot make a single worksheet cell exceed its defined content limit.

Frequently Asked Questions

What is the maximum length of a VBA String?
VBA documentation describes a variable-length string as holding approximately 2 billion characters. That is a theoretical ceiling; available memory and the details of the operation usually determine the practical maximum.

Can an Excel cell hold more than 32,767 characters?
No. A worksheet cell is limited to 32,767 characters. A VBA string can be longer, but store excess text in multiple cells, a file, or another suitable destination.

Does 64-bit Excel remove the VBA string limit?
No. It can provide a larger address space for some workloads, but it does not remove the language’s string constraints, the memory cost of large values, or Excel’s worksheet limits.

How do I check a VBA string’s length?
Call Len(myString). It returns a Long count. Use LenB only when you specifically need a byte count rather than the ordinary character count.

Why does my long text look cut off in Excel?
It may be hidden by the column width or Excel’s in-cell display behavior, even if the full value is stored. Check the Formula Bar and the actual cell value; if the content exceeds 32,767 characters, it cannot all be stored in that one cell.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.