[英]VBA Delete entire row if value in 1 column is greater than the value in another column
I am new to VBA for excel and I am stuck with a little problem. 我是VBA新手,擅长使用Excel,但遇到了一些小问题。 I have to delete an entire row if the value in column D is greater than the value in column E. 如果D列中的值大于E列中的值,我必须删除整行。
The list of data is very long and I will need the action to continue until the data in column C ends. 数据列表很长,我将需要继续操作直到C列中的数据结束。 Any help would be great! 任何帮助将是巨大的!
When deleting rows, start at the bottom and work up or you may skip rows due to the renumbering associated with a newly deleted row. 删除行时,请从底部开始并进行操作,否则,由于与新删除的行相关联的重新编号,您可能会跳过行。
Sub del_D_greater_than_E()
Dim rw As Long
With Worksheets("Sheet5") '<~~ set this properly!
For rw = .Cells(Rows.Count, "C").End(xlUp).Row To 2 Step -1
If .Cells(rw, "D").Value2 > .Cells(rw, "E").Value2 Then
.Rows(rw).EntireRow.Delete
End If
Next rw
End With
End Sub
That should be enough to get you started. 那应该足以让您入门。 You may want to turn off screen updating and calculation during the operation. 您可能要在操作过程中关闭屏幕更新和计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.