|
|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub ykcbf() '//2025.11.5
- Dim tm As Double
- Const bt% = 1
- Const col% = 3
- tm = Timer
- Set d = CreateObject("scripting.dictionary")
- Set sh = ActiveSheet
- With Application
- .ScreenUpdating = 0
- .DisplayAlerts = 0
- .Calculation = xlCalculationManual
- .AskToUpdateLinks = False
- .EnableEvents = 0
- End With
- For Each sht In Sheets
- If InStr("名称关键词|总清单", sht.Name) = 0 Then sht.Delete
- Next
- arr = sh.UsedRange.Value
- zrr = Sheets("名称关键词").UsedRange.Value
- For j = 1 To UBound(zrr, 2)
- s = Replace(zrr(1, j), "关键词", "")
- For i = 2 To UBound(zrr)
- If zrr(i, j) <> Empty Then d(s) = d(s) & "|" & zrr(i, j)
- Next
- Next
- For Each k In d.keys
- ptt = Mid(d(k), 2)
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- m = 0
- For i = bt + 1 To UBound(arr)
- If styes(arr(i, col), ptt) = True Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- End If
- Next
- sh.Copy After:=Sheets(Sheets.Count)
- With Sheets(Sheets.Count)
- .Name = k
- .DrawingObjects.Delete
- .UsedRange.Offset(bt + m).Clear
- .Cells(bt + 1, 1).Resize(m, UBound(arr, 2)) = brr
- End With
- Next
- sh.Activate
- With Application
- .DisplayAlerts = 1
- .ScreenUpdating = 1
- .Calculation = xlCalculationAutomatic
- .AskToUpdateLinks = True
- .EnableEvents = 1
- End With
- Dim msg As String
- msg = "拆分操作完成" & vbCrLf & _
- "┌───────────────────────┐" & vbCrLf & _
- "│ 处理时间: " & Format(Timer - tm, "0.00") & "秒" & vbCrLf & _
- "│ 原始数据: " & UBound(arr) - bt & "行" & vbCrLf & _
- "│ 生成表数: " & d.Count & "个" & vbCrLf & _
- "│ 处理速度: " & Format((UBound(arr) - bt) / (Timer - tm), "0") & "行/秒" & vbCrLf & _
- "└───────────────────────┘"
- MsgBox msg, vbInformation, "执行报告"
- End Sub
- Function styes(st, ptt) As Boolean
- If Len(ptt) = 0 Or Len(st & "") = 0 Then Exit Function
- On Error Resume Next
- With CreateObject("VBScript.RegExp")
- .Pattern = ptt
- .IgnoreCase = True
- styes = .Test(CStr(st))
- End With
- End Function
复制代码
|
|