Last active
March 10, 2016 02:20
-
-
Save toagit/4b88f6e77cfac4c0f2c4 to your computer and use it in GitHub Desktop.
コレクションをセル範囲に設定可能な2次元配列に変換します。
コレクションのvalueには1行分のデータをIndex0から設定してください。
<Collection 配列 変換>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'コレクションをセル範囲に設定可能な2次元配列に変換します。 | |
'コレクションのvalueには1行分のデータをIndex0から設定してください。 | |
Public Function ConvertListToArrayRange(list As Collection) As Variant() | |
Dim rowCnt As Long | |
Dim colCnt As Long | |
rowCnt = list.Count | |
colCnt = UBound(list(1)) | |
Dim arr() As Variant | |
ReDim arr(1 To rowCnt, 0 To colCnt) | |
Dim i As Long | |
For i = 1 To rowCnt | |
Dim j As Long | |
For j = 0 To colCnt | |
arr(i, j) = list(i)(j) | |
Next j | |
Next i | |
ConvertListToArray = arr | |
End Function | |
Public Sub sample() | |
Dim list As New Collection | |
Dim i As Integer | |
For i = 1 To 10 | |
Call list.Add(Array("A" & i, "B" & i)) | |
Next i | |
Range("A1:B10") = ConvertListToArrayRange(list) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment