|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 槐序三冬 于 2024-10-12 22:39 编辑
- Sub prectise()
- Set a = ActiveSheet
-
- 'arr = Array("张", "A", "杨", "777", "B", "C")
- Set rng_0 = Application.InputBox("您打算保留的名字所在列", Type:=8)
-
- col_0 = rng_0.Column
- index_1 = rng_0.Row
- lastcol = a.Cells(index_1, col_0).End(xlToRight).Column - 1
-
- arr = Array(Range(a.Cells(index_1, col_0), a.Cells(index_1, lastcol)))
-
- For i = 1000 To 3 Step -1
- For j = LBound(arr) To UBound(arr)
- If Not IsInArray(a.Cells(i, 2).Value, arr) Then
- a.Range("A" & i & " :N" & i).Delete shift:=xlUp
- End If
- Next
- Next i
- End Sub
- ' 辅助函数:检查值是否在数组中
- Function IsInArray(val As Variant, arr As Variant) As Boolean
- On Error Resume Next
- IsInArray = (Application.Match(val, arr, 0) > 0)
- On Error GoTo 0
- End Function
复制代码 |
|