Error 7, “Out of memory”, is VBA's most misleading message. It fires when VBA cannot allocate something, an array, a string, a stack frame, but on a modern machine with free RAM the real cause is usually a loop that never stops growing something, code running in a 32-bit host with a hard 2 GB ceiling, or the fixed limits inside VBA itself. Treat it as a code bug first and a hardware problem last.
ReDim Preserve inside a loop with a condition that never becomes false grows the array until allocation fails. Log the counter and the array size when debugging.Range("A1").CurrentRegion.Value is fine; reading Columns("A:Z").Value allocates a million-row array for a ten-row sheet.Dim data As Variant
data = ws.Range("A1").CurrentRegion.Value ' sized to the data
' not: data = ws.UsedRange.Value ' UsedRange can be huge
Join once at the end.If small inputs also fail instantly, suspect a corrupt workbook or a broken add-in rather than allocation size: test the same macro in a fresh blank file, and start the host with add-ins disabled. A failure that follows the macro into a blank file is in the code; a failure that stays with one file is in the file.
Does error 7 mean the computer needs more RAM? Almost never. It means VBA's allocation failed inside the host process. The usual causes are a runaway loop, an oversized array or string, or a 32-bit host at its address-space limit, all fixable in code or configuration.
Why does error 7 appear only on large files? Because allocation size scales with the data. Code that loads an entire range or builds one giant string works on small inputs and crosses the limit only when the data grows.