API reference · Arrays

DimSplit

Convert a 2D matrix into a 1D outer array containing one 1D array per row.

FunctionArrays→VariantSource L304

Signature#

VBA
Function DimSplit(ByVal vArr As Variant) As Variant

Parameters#

ParameterVBA typeDefaultDescription
vArrVariantByValRequiredAllocated two-dimensional array to split into row arrays.

Returns#

Variant containing a 1D outer array with the source row bounds. Every inner 1D row array has the source column bounds. Returns Empty for non-arrays or unsupported rank.

Example#

SEE THE TRANSFORMATIONSplit into separate row vectors
Before
transactions2D · 2 × 2

Rows 1..2 · Columns 1..2

row / col12
1“Sales”100
2“Fees”12
After
rows1D outer · (2,)

Outer indices 1..2 · each element is a 1D array

Element 11D · (2,)
12
“Sales”100
Element 21D · (2,)
12
“Fees”12

The outer array has rank 1. Its elements contain independent 1D row arrays, not a second rectangular dimension.

Shaded headers are array indices, not data. Quoted cells are text. Values shown are derived from the source, not an Excel execution.

VBA
Sub ExampleDimSplit()
    Dim a As New Arrays
    Dim transactions As Variant, rows As Variant

    ReDim transactions(1 To 2, 1 To 2)
    transactions(1, 1) = "Sales": transactions(1, 2) = 100
    transactions(2, 1) = "Fees": transactions(2, 2) = 12
    rows = a.DimSplit(transactions)
    Debug.Print rows(1)(1), rows(1)(2) ' Expected: Sales, 100
    Debug.Print a.DimCounter(rows)    ' Expected: 1; inner arrays are separate
End Sub

Behavior and edge cases#

Performance#

O(r × c) element work and O(r × c) output storage, plus an O(c) row template and O(r) outer-array descriptors.

View implementation
VBA
Function DimSplit(ByVal vArr As Variant) As Variant
    'Converts a two-dimensional array into a one-dimensional array of row arrays

    Dim vArr_Template As Variant
    Dim lRow As Long
    Dim lCol As Long
    Dim vArr_Out As Variant

    If Not IsArray(vArr) Then Exit Function
    If Me.DimCounter(vArr) <> 2 Then Exit Function
    ReDim vArr_Out(LBound(vArr, 1) To UBound(vArr, 1))
    ReDim vArr_Template(LBound(vArr, 2) To UBound(vArr, 2))
    For lRow = LBound(vArr_Out) To UBound(vArr_Out)
        vArr_Out(lRow) = vArr_Template
        For lCol = LBound(vArr, 2) To UBound(vArr, 2)
            vArr_Out(lRow)(lCol) = vArr(lRow, lCol)
        Next lCol
    Next lRow

    If IsArray(vArr_Out) Then
        DimSplit = vArr_Out
    End If
End Function