我的以下代码运行良好,但是我想做的是修改代码以将要清除的数据复制到Sheet2,以进一步调查从原始工作表继续清除的情况。代码本身所做的全部是查看G和H。如果H小于G,则清除A:J的内容。我现在想要的是在满足条件的情况下仍然清除内容,但是我也希望将单元格的副本也复制到Sheet2。
Sub ClearRange()
Dim myLastRow As Long
Dim i As Long
Application.ScreenUpdating = False
' Find last row
myLastRow = Cells(Rows.Count, "G").End(xlUp).Row
' Loop through range
For i = 5 To myLastRow
If Cells(i, "H").Value < Cells(i, "G").Value Then Range(Cells(i, "A"), Cells(i, "J")).ClearContents
Next i
Application.ScreenUpdating = True
End Sub
在此先感谢您提供的任何帮助。
您可以只更新代码的这一部分:
' Loop through range
For i = 5 To myLastRow
If Cells(i, "H").Value < Cells(i, "G").Value Then
With Range(Cells(i, "A"), Cells(i, "J"))
.Copy
Sheets("Sheet2").Paste Destination:=Sheets("Sheet2").Range("A" & i)
.ClearContents
End With
End If
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句