質問: _ Cells(i - 1, 4).Value * Cells(i - 1, k).Value _ * Cells(i - 2, 4).Value * Cells(i - 2, k).Value Next Next End Sub ```
回答: Dim i As Long, j As Long, k As Long ' カウント Dim ws1, ws2 As Worksheet Set ws1 = Worksheets("sheet1") '別紙1 Set ws2 = Worksheets("sheet2") '商品情報 Dim cmax, rmax As Long cmax = ws1.Cells(5, Columns.Count).End(xlToLeft).Column rmax = ws1.Cells(Rows.Count, 7).End(xlUp).Row ' 行の挿入 転記 For i = rmax To 7 Step -3 If Cells(i, 5).Value = "在庫" Then '行の挿入 Rows(i).Insert rmax = rmax + 1 End If If Cells(i - 1, 5).Value = "出庫" Then Rows(i - 1).Insert rmax = rmax + 1 End If ' セル値を代入 For k = 6 To cmax Cells(i + 1, k).Value = Cells(i, 4) * Cells(i, k) Next k ' セル値を代入 For k = 6 To cmax Cells(i - 1, k).Value = Cells(i - 2, 4) * Cells(i - 2, k) Next k ' セルの値と数式代入 Cells(i + 1, 5).Value = "出庫金額" Cells(i - 1, 5).Value = "入庫金額" Next i End Sub