Skip to content

Instantly share code, notes, and snippets.

@toagit
Last active March 10, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toagit/4b88f6e77cfac4c0f2c4 to your computer and use it in GitHub Desktop.
Save toagit/4b88f6e77cfac4c0f2c4 to your computer and use it in GitHub Desktop.
コレクションをセル範囲に設定可能な2次元配列に変換します。 コレクションのvalueには1行分のデータをIndex0から設定してください。 <Collection 配列 変換>
'コレクションをセル範囲に設定可能な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