删除具有基于列的值的行 [英] Deleting rows with values based on a column
本文介绍了删除具有基于列的值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我每月有近373,000条电话线.其中,部分的值较低或为空白.我想删除这行.
I have a monthly base with almost 373,000 lines. Of these, part has a low value or is blank. I'd like to erase this lines.
我有部分代码可以删除那些零.如何创建更敏捷地连接空行条件(D列)的代码.
I have part of this code to delete those that have zero. How to create a code that joins the empty row conditions (column D) in a more agile way.
谢谢
Sub DelRowsZero()
Dim i As Long
For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If Cells(i, "D") = 0 Then Rows(i).Delete
Next i
End Sub
推荐答案
我担心375K行,谁知道这需要多长时间才能运行.
I am concerned about the 375K lines, who knows how long this will take to run.
Sub Button1_Click()
Dim i As Long
For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If Cells(i, "D") = 0 Or Cells(i, "D") = "" Then
Rows(i).Delete
End If
Next i
End Sub
我很好奇这是否对其他人有用,它只是使用"replace" 0值替换为空白,然后使用特殊单元格删除空白行.我测试了38K行需要3秒.
I'm curious to know if this works for others, it just uses the "replace" 0 values to blanks, then uses specialcells to delete the blank rows. My test of 38K rows takes 3 seconds.
Sub FindLoop()
Dim startTime As Single
startTime = Timer
'--------------------------
Columns("D:D").Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'---------------------------------
Debug.Print Timer - startTime
End Sub
这篇关于删除具有基于列的值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文