Results 1 to 4 of 4

Thread: Populating 3 Dimension Array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Hi Jacob,

    Good to see that You challenge arrays

    If we don't insist to use an array of a specific datatype then I would prefer to use the following approach:

    Option Explicit
    Sub Variant_Array()
    Dim wsSheet As Worksheet
    Dim rnData As Range
    Dim vaData As Variant
    Dim i As Long, j As Long, k As Long
    Set wsSheet = ActiveSheet
    With wsSheet
        Set rnData = .Range(.Range("A1"), .Range("C65536").End(xlUp))
    End With
    'Read all data into the array.
    vaData = rnData.Value
    'Variant-arrays that reads data from a range is always 1-based.
    Debug.Print LBound(vaData)
    Debug.Print UBound(vaData)
    'Here we make a dummy addition just to loop through the array:
    For j = 1 To 3
        For i = 1 To UBound(vaData)
            vaData(i, j) = vaData(i, j) * 2
        Next i
    Next j
    'Read the revised data back to the range.
    rnData.Value = vaData
    End Sub

    Hi Tommy,

    Long time since I saw a RDO-approach as most people nowdays prefer ADO

    Thank you for reading my post on this subject,
    Dennis
    Last edited by Aussiebear; 04-29-2023 at 10:09 PM. Reason: Adjusted the code tags
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •