pgbigorokuのブログ

プログラムの再利用できそうなコードをアップ

EXCEL VBA 複数データがある場合に複数行に記入する

'複数データがある場合に複数行に記入する
'
'参考
'    Call psubシートの中の部分表の値を並び替え(shtTarget, 11, 3, 0, 11, 3)
'
'2022/8/13
Private Sub psub複数データがある場合に複数行に記入する(ByRef shtTarget As Worksheet, _
                                 ByVal plng対象Row As Long, _
                                 ByVal pint開始Col As Integer, _
                                 ByVal pint終了Col As Integer, _
                                 ByVal pint分割Col As Integer, _
                                 ByVal pstr分割文字 As String)
    Dim ary分割() As String
    Dim intFor As Integer
    Dim intCol As Integer
    
    With shtTarget
        ary分割() = Split(.Cells(plng対象Row, pint分割Col), pstr分割文字)
        For intFor = 0 To UBound(ary分割)
            For intCol = pint開始Col To pint終了Col
                .Cells(plng対象Row + intFor, intCol) = .Cells(plng対象Row, intCol)
                .Cells(plng対象Row + intFor, pint分割Col) = ary分割(intFor)
            Next
        Next
    End With
End Sub