像這樣的東西應該做的伎倆。
確保您與板運行它,你要更新活動的(它使用ActiveSheet
)
Sub InsertAndUpdate()
Dim x As Long
For x = ActiveSheet.UsedRange.Rows.CountLarge To 2 Step -1
If Cells(x, "B").Value = 197 Then
Cells(x + 1, "B").EntireRow.Insert
Cells(x + 1, "B").EntireRow.Insert
Cells(x, "B").EntireRow.Copy Cells(x + 1, "B").EntireRow
Cells(x, "B").EntireRow.Copy Cells(x + 2, "B").EntireRow
Cells(x + 1, "A").Value = DateAdd("m", 1, Cells(x + 1, "A").Value)
Cells(x + 2, "A").Value = DateAdd("m", 2, Cells(x + 2, "A").Value)
End If
Next x
End Sub
您也可以縮短它有點像這樣,但使用嵌套循環的這麼簡單的東西是有點兒MEH
Sub InsertAndUpdate()
Dim x As Long, y As Integer
For x = ActiveSheet.UsedRange.Rows.CountLarge To 2 Step -1
If Cells(x, "B").Value = 197 Then
For y = 1 To 2
Cells(x + y, "B").EntireRow.Insert
Cells(x, "B").EntireRow.Copy Cells(x + y, "B").EntireRow
Cells(x + y, "A").Value = DateAdd("m", y, Cells(x + y, "A").Value)
Next y
End If
Next x
End Sub
結果(由我強調添加的行)