In Excel VBA, a variable-length String can hold roughly 2 billion characters in theory, but available memory and the application impose practical limits. A worksheet cell is much more restrictive: it can contain at most 32,767 characters, so the VBA string limit and the Excel cell limit are not the same thing.
The short answer: VBA strings versus Excel cells
If your question is how long a string variable can be, VBA’s documented upper bound is approximately 2 billion characters for a variable-length string. That is a theoretical ceiling, not a useful promise that every workbook can create or process a string of that size. Memory, other data in Excel, and the way you use the string are likely to become obstacles much sooner.
If your question is how much text fits in one worksheet cell, the answer is 32,767 characters. The limit applies whether you type the text into a cell or try to put it there with VBA. A long string can exist in VBA without being able to fit in one cell.
Those different limits explain many seemingly contradictory answers online. A VBA variable is an in-memory object; a cell is a worksheet value with its own documented specification. Always check the limit of the destination, not only the limit of the variable holding the text.
Variable-length and fixed-length String declarations
Most VBA code uses a variable-length string, declared simply as Dim message As String. Its contents can grow or shrink as you assign text, subject to memory and the practical limits of the operation. For example, a variable can hold a long response assembled from multiple pieces even though no single worksheet cell can hold that whole response.
VBA also supports fixed-length strings, declared with a length after the type:
Dim code As String * 12
This reserves a 12-character string. If you assign fewer characters, the value is padded with spaces; if you assign more, the excess is cut off. Fixed-length strings are a different feature from a variable-length string’s maximum capacity, and they are rarely needed for ordinary Excel automation. VBA documentation describes their maximum as approximately 65,400 characters, far below the theoretical maximum for a variable-length string.
For general text processing, choose As String without a fixed length. A fixed-length declaration can silently produce a shorter value than expected, which makes it a poor choice when text length is unpredictable.
What Len counts, and what it does not
Use Len to check the length VBA reports for a string. For example, if message contains the text Report ready, Len(message) returns 12. The function is useful for checking whether a value exceeds a worksheet cell’s 32,767-character capacity before writing it.
Len is a character-counting tool, not a measure of the string’s total memory use. VBA stores strings using Unicode, and a character outside the Basic Multilingual Plane, such as some emoji, is represented by a surrogate pair. Such a character can occupy two UTF-16 code units, so counts and text slicing around these symbols may need extra care. If exact byte size matters, LenB reports the number of bytes used to represent a string in memory; it should not be confused with the number of characters that a worksheet cell accepts.
For ordinary English text, Len is generally the practical check for the cell limit. For international text, emoji, or text being exchanged with another system, test representative data rather than assuming that character count, visible symbols, and storage units are interchangeable.
Worksheet cells and formulas have separate limits
Excel’s cell-content limit is 32,767 characters per cell. That limit concerns the value stored in a cell, not how many characters VBA can temporarily hold. A cell may also display less text in the grid than it contains; inspect the formula bar or the value itself when checking a long entry.
Formulas have a separate limit: a formula can contain up to 8,192 characters. This is the length of the formula expression, not the maximum length of a text result. A formula shorter than that can return a longer text result, but the resulting cell value still cannot exceed the cell-content limit. Conversely, a short result does not make an overlong formula acceptable.
Excel also has limits on other worksheet resources, including rows and columns, but those do not raise the per-cell character limit. If a report or imported record exceeds 32,767 characters, it needs a different layout or storage destination rather than a larger cell.
What happens when VBA writes too much text to a cell?
A string assignment to a cell cannot make that cell store more than Excel’s allowed maximum. Depending on the exact operation and how the text is passed, an attempt to write an oversized value can fail or result in text being cut off. Do not rely on a particular failure behavior as a way to detect the problem: check the length first and decide explicitly how the text should be handled.
Also distinguish between writing a value and displaying it. Text may be present in the cell but not all visible in the grid because the column is narrow, the row is short, or the cell contains a large amount of text. Increasing the column width or using Wrap Text can help with visibility, but neither setting increases the 32,767-character storage limit.
Before writing, consider what the recipient needs. If the text is a note intended to be read in the worksheet, splitting it into meaningful parts may be more useful than filling one cell to its maximum. If it is a large source document or an API response, keeping it in a text file or database may be more appropriate than treating a worksheet as a long-text store.
Splitting a long string across cells
When worksheet storage is required, one straightforward approach is to split the string into chunks of no more than 32,767 characters and place each chunk in a separate cell. The following example creates a 70,000-character sample and writes it to column B, starting at B1. In a real macro, replace the sample assignment with the process that creates or loads your text.
Save a copy of the workbook before running a macro that writes to cells. VBA macros cannot be undone with Ctrl+Z, and this example overwrites values in column B.
Sub SplitLongTextAcrossCells()
Dim sourceText As String
Dim startAt As Long
Dim outputRow As Long
Dim ws As Worksheet
' Create sample text; replace this with your actual source.
sourceText = String$(70000, "x")
Set ws = ActiveSheet
outputRow = 1
' Write chunks that fit within one cell.
For startAt = 1 To Len(sourceText) Step 32767
ws.Cells(outputRow, 2).Value2 = Mid$(sourceText, startAt, 32767)
outputRow = outputRow + 1
Next startAt
End Sub
For this example, the first two cells receive 32,767 characters each and the third receives 4,466, for 70,000 characters total. The macro uses rows in column B, so check that those cells are available before running it. If you later need to rebuild the original string, concatenate the chunks in their original order.
There is a Unicode caveat: splitting at a fixed code-unit position can separate the two halves of a surrogate pair. That is uncommon in many datasets but can affect some emoji and other supplementary characters. If the text includes such symbols and must remain intact, split at a safe character boundary or store the original text in a format designed for it.
Common causes of apparent string-limit problems
- Confusing a cell with a variable: A variable can hold much more than one cell can store. Moving the value into a cell is where the worksheet limit matters.
- Using a fixed-length declaration: A declaration such as
String * 12pads or truncates to its declared length. Check the declaration if text is unexpectedly shortened. - Assuming the grid shows the whole value: A narrow column or the worksheet’s display behavior can hide text without changing the stored value. Check the formula bar or read the cell value in VBA.
- Mixing up formula and result limits: The 8,192-character formula limit is not the same as the 32,767-character cell-content limit.
- Ignoring memory use: A large string consumes memory, and copying it into another variable or a Variant array can require additional memory. A theoretical language limit does not guarantee that a large operation will succeed on a particular computer.
Choosing where to put very long text
For up to 32,767 characters that users need to view alongside spreadsheet data, a cell may be suitable. For longer text, choose storage based on how it will be searched, edited, shared, and preserved. Splitting across cells is convenient for worksheet workflows, but it adds reconstruction and ordering considerations.
A plain-text file is often a better fit for a large log, document, or raw response. A database may suit structured records that need searching and updates. If a workbook must carry the text, splitting it into rows or columns can work, provided the workbook documents how the pieces fit together. Keep an identifier and sequence number with each piece if multiple long records are stored.
Large in-memory strings can also make a workbook slower or less reliable, especially if code repeatedly copies them or processes many records at once. Process data in smaller pieces where practical, and avoid loading a whole large file into a worksheet simply because VBA can hold more text than a cell can.
Frequently Asked Questions
What is the maximum length of a VBA String?
A variable-length VBA String is documented as holding approximately 2 billion characters in theory. In practice, available memory and the operation being performed usually matter more than that nominal ceiling.
Can an Excel cell hold more than 32,767 characters using VBA?
No. VBA does not increase a worksheet cell’s capacity. Store the text elsewhere or divide it across multiple cells if the complete value must be retained in the workbook.
Does Len count spaces and punctuation?
Yes. Len counts spaces and punctuation as part of the string, along with letters and digits. Unicode characters represented by surrogate pairs can require special care when interpreting the count.
What is the difference between Len and LenB in VBA?Len returns the string length in characters as VBA counts it; LenB returns the number of bytes used to represent the string in memory. Neither changes the maximum length of an Excel cell.
Can I increase the 32,767-character cell limit?
No worksheet setting or VBA declaration raises the per-cell limit. Use multiple cells, a text file, or another storage system when a value is longer.
Is the limit different in Excel for Mac or Excel for the web?
The 32,767-character worksheet cell limit is an Excel specification, not a Windows-only VBA setting. Excel for the web does not run VBA macros; to run VBA, use the desktop Excel application. Macros also require Excel for Mac on the desktop, with platform-specific differences possible in VBA features and integrations.
Related
- Excel Slicer: Group Dates by Month
- Excel Slicer Colors: How to Change and Customize Them
- Excel Slicer: Connect One Slicer to Multiple PivotTables
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel Macro Filter: How to Automate Data FilteringTo filter a worksheet with a macro, use VBA’s AutoFilter method on a range that includes its header…
- VBA Find: How to Handle a Failed SearchIn Excel VBA, handle a failed Range.Find search by checking whether its result is Nothing before using it.…
- Excel VBA: How to Enable AutoFilterTo enable AutoFilter with VBA, select the worksheet range that includes the column headers and run its AutoFilter…
- VBA Range Union: Combine Separate Ranges in ExcelIn VBA, use Application.Union to combine two or more ranges on the same worksheet into one Range object,…
- VBA Find Last Row: Reliable Methods and ExamplesIn VBA, find the last row in a particular column with ws.Cells(ws.Rows.Count, "A").End(xlUp).Row. To find the last row…
- Refresh Pivot Table Using VBA: Code and TipsTo refresh a PivotTable with VBA in Excel for Microsoft 365 on Windows, call its RefreshTable method; to…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.