|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 dlmuxqh 于 2018-7-11 14:09 编辑
利用VBA,对工作表进行以下操作:按:筛选词 工作表里的筛选词,把 数据 工作表中A列包含筛选词的所在行复制到同一个新工作表,新工作表以“特殊”命名,同时删除 数据 工作表里包含筛选词所在行。
下方代码仅可实现筛选+复制功能,麻烦各位大佬在此代码的基础上增加删除功能,谢谢各位啦~~。附件已上传
Sub xqh()
Dim arr, brr, sht As Worksheet, i, j&, k&
Dim d As Object
On Error Resume Next
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
arr = Sheets("筛选词").[a1].CurrentRegion
With Sheets("数据")
brr = .[a1].CurrentRegion
End With
ReDim crr(1 To UBound(brr), 1 To UBound(brr, 2))
For n = 1 To UBound(arr)
For i = 1 To UBound(brr)
If InStr(brr(i, 2), arr(n, 1)) Then
k = k + 1
For c = 1 To UBound(brr, 2)
crr(k, c) = brr(i, c)
Next
End If
Next
Next
Set sht = Sheets.Add(, Sheets(Sheets.Count))
sht.Name = "特殊"
' sht.[a1].Resize(UBound(crr), UBound(crr, 2)) = crr
sht.[a1].Resize(k, UBound(brr, 2)) = crr
MsgBox "OK"
Set d = Nothing
Application.ScreenUpdating = True
End Sub
|
|