有15个csv文件。每个文件有8000行。在所有文件中,A列包含数字或“删除”。必须删除值为“删除”的行。以下是缓慢的。这毫无意义。还有其他建议吗?
For j = lastRow To 1 Step -1
If Wb1.Worksheets(1).Cells(j, 1).Value = "Delete" Then
Wb1.Worksheets(1).Rows(j).Delete
lastRow = Wb1.Worksheets(1).Cells(Cells.Rows.Count, "A").End(xlUp).Row
End If
Next j
答案 0 :(得分:1)
试试这样。
ActiveSheet.AutoFilter.Range.Offset(1,0).Rows.SpecialCells(xlCellTypeVisible).Delete(xlShiftUp)
或... 使用SpecialCells仅删除自动过滤后可见的行:
ActiveSheet.Range("$A$1:$I$" & lines).SpecialCells _
(xlCellTypeVisible).EntireRow.Delete
答案 1 :(得分:0)
这种方法正常工作(5分钟,15 csv,每行9000行)
For j = lastRow To 1 Step -1
ValueToFind = "Delete" 'look at this value
With Wb.Worksheets(1).Range("A:A") 'searches all of column A or whatever column
Set Rng = .Find(What:=ValueToFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
GoTo Next_Row 'value found
Else
Wb.Worksheets(1).Rows(j).Delete
End If
End With
Next_Row:
Next j