excel - 直到循环执行缓慢 - 偏移和选择的替代方案?
问题描述
代码循环遍历相当大的数据(1000 行乘 20 列)并删除单元格中没有错误但当前需要 20 分钟执行的行。寻找一种通过消除代码中对偏移和选择的需要来加速该过程的方法。
我曾尝试在代码前后关闭/打开自动计算,但这并没有明显影响运行时。屏幕更新已关闭。
Range("A6").Select
Do Until IsEmpty(ActiveCell)
If IsError(ActiveCell) Then
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.EntireRow.Delete
End If
Loop
保留区域 A 中的单元格为 N/A (IsError) 的行。按预期运行,但需要整整 20 分钟才能运行。
任何帮助表示赞赏。
解决方案
SpecialCells 可以快速查找所有返回布尔值、数字或文本的公式,同时排除错误。
dim rng as range
with worksheets("sheet1")
with .range(.cells(6, "A"), .cells(.rows.count, "A").end(xlup))
on error resume next
set rng = .specialcells(xlCellTypeFormulas, xlLogical+xlNumbers+xlTextValues)
on error goto -1
if not rng is nothing then
rng.entirerow.delete
end if
end with
end with
推荐阅读
- ios - Swift - 过滤带有属性问题的自定义数组
- pyspark - Pyspark:将数据框写入 Cassandra 表不起作用
- php - 嵌入式表单 Symfony
- c# - 用于在工具箱中为自定义控件库添加选项卡的 Visual Studio 扩展
- kubernetes - 错误:无法启动补丁证书循环 mutatingwebhookconfigurations.admissionregistration.k8s.io “istio-sidecar-injector”未找到
- css - dropzone 图标显示在 dropzone 之外
- gekko - 使用 Gekko opt 包,是否可以估计解决脚本需要多少内存?
- ruby-on-rails - 命令行终端餐厅应用程序错误
- rest - 如何通过 DevOps REST API 获取特定 Commit 的构建列表
- mysql - 根据另一个表的映射值来获取列的最小值的最有效查询