简体   繁体   English

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

[英]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.

相关问题 如果列中有0值,则excel vba删除整行 - excel vba delete entire row if there is 0 value in a column 如果工作簿中所有工作表的值都大于1,则Excel中要删除A:A列中的行的VBA代码是什么? - What is the VBA code in Excel to Delete row(s) in column A:A if value is greater than 1 for all sheets in workbook VBA代码删除整个行,如果该行的特定列的值在另一个工作表中不匹配 - Vba code to delete the entire row if value for particular column for that row does not match in another worksheets VBA 尝试遍历列并删除整行(如果它们包含值) - VBA Trying to loop through a column and delete the entire row if they contain a value 在Excel VBA列中搜索大于1的值 - Searching for greater than 1 value in a column Excel VBA 使用VBA根据一列中的时间和另一列中的值删除行 - Using VBA to Delete a Row Based on Time in One Column and Value in Another 如果同一行中的另一个单元格的值大于0,则仅索引另一张工作表中一列的单元格 - Index only cells in a column from another sheet if another cell in same row has a value greater than 0 Excel VBA基于列值删除行 - Excel VBA Delete Row based on column value VBA Excel根据列中的值删除行 - VBA Excel Delete Row Based on Value in Column 如果给定列中的值大于 0,如何将行的不一定连续的部分复制到另一个工作表? - How to copy a non necessarily contiguous portion of a row to another sheet if a value from a given column is greater than 0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM