2017-07-08 8 views
0

Ich versuche, Werte einer Spalte in einem 2-dim-Array (0 bis 1, 0 bis "Länge meiner Spalte").excel-vba Einspaltige bis multidimensionale Array

Ich brauche etwas wie folgt aus:

arr(0, 0) = value of B4 
arr(1, 0) = value of B5 
arr(0, 1) = value of B6 
arr(1, 1) = value of B7 
... 
arr(0, n) = value of Bn 
arr(1, last row of my column range) = value of last B 

Kann mir jemand sagen, welche Funktion ich verwenden muss?

Antwort

0

Die folgende Code-Schleifen durch jede Zelle in Spalte B, bei B4 beginnend und ordnet ihre Werte zu dem Array aResults, wie Sie beschrieben haben ...

Dim aResults() As Variant 
Dim rRange As Range 
Dim nCols As Long 
Dim i As Long 

Set rRange = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row) 

nCols = rRange.Cells.Count \ 2 
nCols = nCols + (rRange.Cells.Count Mod 2) 

ReDim aResults(1, nCols - 1) 

For i = 0 To rRange.Cells.Count - 1 
    'Debug.Print i Mod 2, i \ 2, rRange(1).Offset(i).Value 
    aResults(i Mod 2, i \ 2) = rRange(1).Offset(i).Value 
Next i