2 Dimensional array from range

calendar_today Asked Aug 28, 2013
thumb_up 34 upvotes
history Updated April 14, 2026

Direct Answer

Assuming your spreadsheet looks kind of like this There is a really easy way to stick that in a 2D array Dim arr as Variant arr = Range("B6:H14").Value The easiest way to print…. This is a 3-line Excel VBA snippet, ranked #37th of 303 by community upvote score, from 2013.


The Problem (Q-score 2, ranked #37th of 303 in the Excel VBA archive)

The scenario as originally posted in 2013

I have text data in Excel worksheet in the cells B6:H14.

Some rows will have 2 cells with contents while others have 4 and some will have 7. How do I copy these to a 2 dimensional array? I know the dimensions already and so, I am ok with the dimensions not being declared dynamic code.

Do I need to use a loop (which I am currently planning to use)?

Or is there an easier / more elegant way?

Why community consensus is tight on this one

Across 303 Excel VBA entries in the archive, the accepted answer here holds elite answer (top 10 %%) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — elite answer (top 10 %%) (+34)

3-line Excel VBA pattern (copy-ready)

Assuming your spreadsheet looks kind of like this

spreadsheet

There is a really easy way to stick that in a 2D array

Dim arr as Variant
arr = Range("B6:H14").Value

The easiest way to print this array back to spreadsheet

Sub PrintVariantArr()

    Dim arr As Variant
    arr = Range("B6:H14")

    Range("B16").Resize(UBound(arr, 1), UBound(arr, 2)) = arr

End Sub

Or you can iterate/loop the array

Sub RangeToArray()

    Dim arr As Variant
    arr = Range("B6:H14").Value
    Dim r As Long, c As Long

    r = 16
    c = 2

    Dim i, j
    For i = LBound(arr, 1) To UBound(arr, 1)
        For j = LBound(arr, 2) To UBound(arr, 2)
            Cells(r, c) = arr(i, j)
            c = c + 1
        Next j
        c = 2
        r = r + 1
    Next i

End Sub

And your array printed back to the spreadsheet

result

Loop-performance notes specific to this pattern

The loop in the answer iterates in process. On a 2026 Office build, setting Application.ScreenUpdating = False and Application.Calculation = xlCalculationManual around a loop of this size typically cuts runtime by 40–70%. Re-enable both in the Exit handler.


When to Use It — classic (2013–2016)

Ranked #37th in its category — specialized fit

This pattern sits in the 90% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.

What changed between 2013 and 2026

The answer is 13 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Why is this answer the top decile of Excel VBA Q&A?
expand_more

Answer score +34 vs the Excel VBA archive median ~11; this entry is elite. The score plus 2 supporting upvotes on the question itself (+2) means the asker and 33 subsequent voters all validated the approach.

Does the 3-line snippet run as-is in Office 2026?
expand_more

Yes. The 3-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2013 — what’s changed since?
expand_more

Published 2013, which is 13 year(s) before today’s Office 2026 build. The Excel VBA object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which Excel VBA pattern ranks just above this one at #36?
expand_more

The pattern one rank above is “When should an Excel VBA variable be killed or set to Nothing?”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 2, Answer-score 34, original post 2013, ranked #37th of 303 in the Excel VBA archive. Last regenerated April 14, 2026.