我是VBA新手,但是我遇到了一个小问题.如果D列中的值大于E列中的值,我必须删除整行.
I am new to VBA for excel and I am stuck with a little problem. I have to delete an entire row if the value in column D is greater than the value in column E.
数据列表很长,我将需要继续操作直到C列中的数据结束.任何帮助都会很棒!
The list of data is very long and I will need the action to continue until the data in column C ends. 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.
更多推荐
VBA如果第一列中的值大于另一列中的值,则删除整行
发布评论