如果值与数组中的值匹配,请删除列中的单元格

时间:2018-11-13 18:44:35

标签: excel vba excel-vba

我试图让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

0 个答案:

没有答案
相关问题