Runtime Error 14: “Out of string space,” explained and fixed

Error 14, “Out of string space”, is the string-specific sibling of out of memory. VBA keeps strings in a managed pool, and this error fires when string data grows past what that pool can hold, most often one giant string assembled piece by piece, or an array of strings with no upper bound on its growth. The code is asking for more text storage than the design allows.

For people who just run the program

  1. Note the size of what was being processed. Error 14 shows up on the biggest report, the longest export, the full-history pull, not on everyday small jobs.
  2. Run the job in smaller slices. One month at a time instead of a year, one department instead of all. If small slices pass, the code is hitting a growth limit, not a broken file.
  3. Save and close other documents. It will not cure a runaway build, but it rules out general memory pressure before the maintainer digs in.
  4. Report the data volume involved. “Fails at about 40,000 rows” is the single most useful fact for whoever fixes this.

For people who write the code

  1. Stop concatenating onto one string in a loop. Every s = s & piece copies the whole accumulated text. At scale this is both slow and space-hungry; it is the number one cause of error 14.
  2. Dim parts() As String, i As Long
    ReDim parts(1 To rowCount)
    For i = 1 To rowCount
        parts(i) = BuildLine(i)
    Next i
    result = Join(parts, vbCrLf)   ' one allocation at the end
  3. Stream output instead of building it. Write lines to the file, cell, or control as they are produced rather than assembling the entire document in memory first.
  4. Cap collection sizes. An array or dictionary that gains an entry per record with no check will eventually ask for more string space than exists. If the count can grow forever, the design, not the limit, is wrong.
Error 14 in a 32-bit host arrives much sooner than people expect. String storage lives inside the same limited address space as everything else. Code that “worked last year” fails when the data doubles, with no code change at all.

If it still happens

If the volume is modest and error 14 still fires, look for accidental exponential growth: a string variable accidentally concatenated to itself, or a replace loop whose replacement contains the search text, so each pass makes the string longer. Print the length at intervals; doubling lengths expose it immediately.

Common questions

What is the difference between error 7 and error 14? Error 7 is a general allocation failure; error 14 is specifically about string storage. In practice both point at unbounded growth, and both are usually fixed by restructuring how the code accumulates data.

Can a single string really be too big? Yes. A string approaching the process memory limit, built by repeated concatenation, can trigger error 14 on its own, especially in a 32-bit host application.

Related errors

Runtime Error 7 · Runtime Error 28 · Runtime Error 62