Runtime Error 10: “This array is fixed or temporarily locked,” explained and fixed

Error 10, “This array is fixed or temporarily locked”, appears when code tries to resize or erase an array that VBA has frozen. The array might be declared with fixed bounds, currently referenced inside a With block, or handed over to something (a control, a library call) that pins it in place. It is a code bug: the resize is aimed at an array that was never meant to move.

For people who just run the program

  1. Note the action that triggered it. Error 10 tends to appear at one specific step, importing, sorting, or loading a list, where the macro tries to rebuild an array.
  2. Retry with a smaller or simpler data set. Some code paths only hit the locked-array resize when a certain branch runs, and knowing which data triggers it helps the maintainer.
  3. Do not rename or move the file mid-run. If the macro drives an external component, changing the file underneath it can leave arrays pinned by that component.
  4. Send the error number and the step. The fix is a declaration or ordering change in the code, and the step identifies which array.

For people who write the code

  1. Declare resizable arrays as dynamic. Dim a() can be ReDimmed; Dim a(1 To 10) cannot. A ReDim aimed at the second form is error 10 every time.
  2. Dim items() As String        ' dynamic: ReDim is allowed
    ReDim items(1 To count)
    ' Dim items(1 To 10) As String  ' fixed: ReDim raises error 10
  3. Do not ReDim an array inside its own With block. While With arr is active the array is temporarily locked. Finish the With block, resize, then re-enter if needed.
  4. Copy before resizing arrays owned by something else. An array returned by a property or bound to a control may be locked by its owner. Assign it to a local dynamic array, resize the copy, and assign back.
  5. Check Erase calls too. Erase on a fixed-size array reinitializes it legally, but on a locked array it raises the same error 10; the lock, not the verb, is the problem.
Declaring everything as a Variant does not dodge error 10. A Variant holding a fixed or locked array is still fixed or locked. The fix is at the declaration and ownership level, not the type level.

If it still happens

If the array is dynamic and not in a With block, the lock is coming from outside VBA: an array passed ByRef into a DLL call or bound to a form control stays pinned until that call returns or the binding is released. Resize a copy, or complete the external call first.

Common questions

What does temporarily locked mean in practice? VBA freezes an array while something else is relying on its current memory: a With block referencing it, a control displaying it, or a library call using it. The lock ends when that use ends.

Is error 10 caused by the data? No. The data can trigger the code path, but the cause is structural: code tried to change the size of an array that was declared fixed or is currently locked.

Related errors

Runtime Error 9 · Runtime Error 381 · Runtime Error 457