0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mm vbaの基本 任意のシートの任意の列の値を別のシートの各行に数行間隔で貼り付け

Posted at

・Sheet3のB列(1行目から5行目)の値をSheet4のA列に6行間隔毎で張り付ける。

qiita.bas
Sub CopyAndPasteWithInterval()
    Dim sourceWs As Worksheet
    Set sourceWs = ThisWorkbook.Sheets("Sheet3") ' コピー元のシート

    Dim targetWs As Worksheet
    Set targetWs = ThisWorkbook.Sheets("Sheet4") ' 貼り付け先のシート

    Dim sourceRow As Integer
    Dim targetRow As Integer
    Dim i As Integer

    sourceRow = 1 ' コピー元の開始行
    targetRow = 2 ' 貼り付け先の開始行

    For i = 0 To 4 ' 0から4までのループで、合計5行分を処理
        sourceWs.Cells(sourceRow + i, 2).Copy ' B列のsourceRow+i行目をコピー
        targetWs.Cells(targetRow, 1).PasteSpecial Paste:=xlPasteAll ' A列のtargetRow行目に貼り付け

        targetRow = targetRow + 6 ' 次の貼り付け先行は現在の行から6行後
    Next i

    Application.CutCopyMode = False
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?