VBA如果第一列中的值大于另一列中的值,则删除整行 [英] VBA Delete entire row if value in 1 column is greater than the value in another column

查看:70
本文介绍了VBA如果第一列中的值大于另一列中的值,则删除整行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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如果第一列中的值大于另一列中的值,则删除整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆