excel - 如果值与数组中的值匹配,则删除列中的单元格
问题描述
我试图让 VBA 删除 Z 列中的单元格。我找到了一个我一直在玩的代码片段(如下),但是它非常慢。必须有更快的方法来执行此任务。我知道使用.Select
会减慢速度,但现在,它可以工作。任何提高速度的想法将不胜感激。此外,添加动态行数来设置范围也很棒。
Sub DeleteValues() 'This works but is really slow
Dim x As Integer
Dim i As Integer
Dim Arr(1 To 7) As String
Arr(1) = "First search item"
Arr(2) = "Second search item"
Arr(3) = "Third search item"
Arr(4) = "Fourth search item"
Arr(5) = "Fifth search item"
Arr(6) = "Sixth search item"
Arr(7) = "Seventh search item"
Range("Z1").Select
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
For x = 1 To 70 'for 70 rows
For i = 1 To 7 'number of items in the Array
If ActiveCell.Value = Arr(i) Then
ActiveCell.Delete
End If
Next i
ActiveCell.Offset(1, 0).Select
Next x
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
解决方案
推荐阅读
- python-3.x - 在 Ubuntu 终端中将带有文件路径的文件传递给 Python 以分析每个文件?
- visual-studio - SSIS 安装 VS 2019 失败
- php - 通过 PHP 在 JSON 中查找和替换数据
- sql-server - 如何逐一删除行以使触发器不抛出错误
- php - 如何检查关联数组中是否存在值
- django - static() 辅助函数 django
- function - 我无法添加两个不同的功能节点
- python - 非本地主机上的套接字python
- c - 结构类型的完成是否对该类型的所有先前声明在同一范围内有效?
- python - 根据另一个数据帧的日期范围对多个 Dask 数据帧进行切片的最快方法