VBA如果第一列中的值大于另一列中的值,则删除整行

编程入门 行业动态 更新时间:2024-10-28 02:22:21
本文介绍了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如果第一列中的值大于另一列中的值,则删除整行

本文发布于:2023-07-26 07:08:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1214879.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!