必需: 我试图创建过滤细胞I22所有零值的宏,选择所有的那些行,删除它们,然后再重新筛选。删除“零”和“N/A”,从过滤器的行 - VBA
我有什么: 目前我在做这两个不同的步骤,因为在一个步骤做这需要几个小时(因为它删除每行排)
码(1 ):自动过滤器为'零'和'N/A',选择它们并清除所有内容。接下来清除过滤器并从最大到最小排序。这样,excel不需要分别删除每一行,从而使进程更快。
代码(2):删除所有空白行。
我有这样的印象,考虑到它需要做的任务,这段代码不是完全有效和太长。是否有可能将这些组合成一个代码?
码(1)
Sub clearalldemandzero()
clearalldemandzero Macro
ActiveWindow.SmallScroll Down:=15
Range("A26:EU26").Select
Selection.AutoFilter
ActiveWindow.SmallScroll ToRight:=3
ActiveSheet.Range("$A$26:$EU$5999").AutoFilter Field:=9, Criteria1:="=0.00" _
, Operator:=xlOr, Criteria2:="=#N/A"
Rows("27:27").Select
Range("D27").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Clear
ActiveSheet.ShowAllData
Range("H28").Select
ActiveWorkbook.Worksheets("Solver 4").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Solver 4").AutoFilter.Sort.SortFields.Add Key:= _
Range("I26:I5999"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Solver 4").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
码(2)
Sub DeleteBlankRows3()
'Deletes the entire row within the selection if the ENTIRE row contains no data.'
Dim Rw As Range
If WorksheetFunction.CountA(Selection) = 0 Then
MsgBox "No data found", vbOKOnly, "OzGrid.com"
Exit Sub
End If
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
Selection.SpecialCells(xlCellTypeBlanks).Select
For Each Rw In Selection.Rows
If WorksheetFunction.CountA(Selection.EntireRow) = 0 Then
Selection.EntireRow.Delete
End If
Next Rw
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
以相反的顺序删除行肯定会有所帮助。 – Bathsheba
如果可以接受,您也可以禁用屏幕更新。这将大大缩短执行时间。在你的'clearalldemandzero'子文件的开始部分放入这个文本'Application.ScreenUpdating = False',然后在子文件末尾放上'Application.ScreenUpdating = true',看看是否有所作为。基本上,excel将完成所有更改,并在完成后更新屏幕。所以所有的行看起来像是一次删除。 – andrew