|
拆分速度有点慢,仅供参考。。。
- Sub ykcbf() '//2024.11.12
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- Set sh = ThisWorkbook.Sheets("CPK分析报告")
- f = p & "\工序\CPK数据记录表(大沟).xlsx"
- p2 = p & "报告存储单"
- Dim tm: tm = Timer
- Set wb1 = Workbooks.Open(f, 0)
- For Each sht In wb1.Sheets
- With sht
- For j = 3 To 22 Step 5
- st = .Cells(4, j).Value
- l = InStr(st, "(")
- st = Left(st, l - 1)
- d(st) = j
- Next
- End With
- Next
- For Each k In d.keys
- m = 0
- ReDim brr(1 To 10000, 1 To 1)
- For Each sht In wb1.Sheets
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- r1 = .Columns(1).Find("No.").Row
- arr = .[a1].Resize(r, 22)
- For j = 3 To UBound(arr, 2) Step 5
- st = .Cells(4, j).Value
- l = InStr(st, "(")
- st = Left(st, l - 1)
- If st = k Then
- For i = r1 + 1 To UBound(arr)
- For x = 1 To 5
- m = m + 1
- brr(m, 1) = arr(i, j + x - 1)
- Next
- Next
- Exit For
- End If
- Next
- End With
- Next
- sh.Copy
- Set wb = ActiveWorkbook
- With wb.Sheets(1)
- .Name = k
- For Each btn In .OLEObjects
- If btn.Name = "拆分" Then
- btn.Delete
- Exit For
- End If
- Next btn
- .[d12].Resize(m, 1) = brr
- End With
- wb.SaveAs p2 & "CPK分析报告(" & k & ")"
- wb.Close
- Next
- wb1.Close 0
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|