|
Sub DltRow20()
Dim Arr, x&, i&, R, Brr, K&, Book&, j&
R = Array("星", "空", "excel") '关键词装入数组r
Arr = [a1].CurrentRegion
'数据源装入数组arr。
ReDim Brr(1 To UBound(Arr), 1 To UBound(Arr, 2))
For i = 2 To UBound(Arr)
'遍历数组arr
Book = 0 '标记值初始化0
For j = 1 To UBound(Arr, 2)
For x = 0 To UBound(R)
'遍历R查看是否包含关键词
If InStr(1, Arr(i, j), R(x), vbTextCompare) > 0 Then
Book = 1: Exit For
End If
'是否包含数组r中的关键词,匹配模式不区分字母大小写,如果包含则标记Book=1
'Exit For查询到结果则退出遍历R,避免无谓循环,提高代码效率
Next
If Book = 1 Then Exit For
Next j
If Book = 0 Then
'如果没有包含关键词,则Book为0,保留该行数据,装入结果数组brr
K = K + 1 '累加行数
For j = 1 To UBound(Arr, 2)
'遍历arr该行数据装入brr
Brr(K, j) = Arr(i, j)
Next
End If
Next
[a1].CurrentRegion.ClearContents
'清除原数据
If K > 0 Then [a1].Resize(K, UBound(Brr, 2)) = Brr
'将结果数组放回单元格区域
MsgBox "处理完成。"
End Sub
|
|