我在这里要完成的是一个VBAmacro,用于复制下面所选行上方的四行。
这是我的代码:
Sub dural()
Dim s2 As Worksheet, s3 As Worksheet
Set s2 = ActiveSheet
Set s3 = Sheets("New Sheet")
Dim K As Long, N As Long, i As Long
K = 1
N = s2.Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 To N
With Cells(i, "C")
If .Value = "Scheduled Break" Then
.EntireRow.Copy s3.Cells(K, 1)
K = K + 1
End If
End With
Next i
ActiveCell.Offset(-2, 0).Select
End Sub
复制的行是“Scheduled Break”。我需要做的就是复制目标行上方的四行和“预定中断”一行。
答案 0 :(得分:0)
更改为s2.Range(行(i - 4),行(i))。复制s3.Cells(K,1)
Scott Craner回答我引用它