銀河鉄道

【VBA】一次元配列を縦方向にシートに貼り付け【範囲をリサイズする】

サムネイル
一次元配列を縦に貼り付ける

セル範囲をリサイズして一次元配列を貼り付ける

transposeして縦に貼り付ける

Public Sub PasteToCellResize1AryForY( _
                                        ByVal ws As Worksheet, _
                                        ByVal row As Long, _
                                        ByVal col As Long, _
                                        ByRef ary As Variant)

    Dim firstY As Long: firstY = LBound(ary)
    Dim Y As Long: Y = UBound(ary)
    
    '配列が0始まりの場合は1を足す
    If firstY = 0 Then Y = Y + 1
    
    ws.Cells(row, col).Resize(Y, 1).value = WorksheetFunction.Transpose(ary)
End Sub

呼び出し方

		Call PasteToCellResize1AryForY(Sheet1, 1, 1, ary)

その他の貼り付け

横方向の場合

二次元配列の場合

関連記事

要素数の取得

中身の操作

データの取得

著者

author
月うさぎ

編集後記:
この記事の内容がベストではないかもしれません。

記事一覧