|
代码如下:
- Sub ykcbf() '//2023.2.14
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim arr, brr(1 To 1000, 1 To 10), d
- Set d = CreateObject("scripting.dictionary")
- Dim tm: tm = Timer
- With Sheets("耗材及服务商")
- r = .Cells(Rows.Count, 1).End(xlUp).Row
- arr = .[a1].Resize(r, 1)
- End With
- For i = 2 To UBound(arr)
- s = Trim(arr(i, 1))
- If s <> "" Then
- d(s) = s
- End If
- Next i
- With Sheets("汇总数据")
- r = .Cells(Rows.Count, 2).End(xlUp).Row
- c = .Cells.Find("*", SearchOrder:=xlByColumns, searchdirection:=xlPrevious).Column
- arr = .[a1].Resize(r, c)
- End With
- For Each k In d.keys
- m = 0
- For i = 2 To UBound(arr)
- For j = 6 To UBound(arr, 2)
- s = Trim(arr(i, j))
- If s <> Empty Then
- If s = k Then
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = arr(i, 2)
- brr(m, 4) = arr(i, 3)
- brr(m, 5) = arr(i, 4)
- brr(m, 10) = arr(i, 5)
- End If
- End If
- Next
- Next
- If m > 0 Then
- Sheets("样本").Copy
- Set wb = ActiveWorkbook
- Set sht = wb.Worksheets(1)
- With sht
- .Name = k
- .[a4] = "工作簿名称《" & k & "》"
- .[a7].Resize(m, UBound(brr, 2)) = brr
- .[a7].Resize(m, UBound(brr, 2)).Columns.AutoFit
- End With
- wb.SaveAs Filename:=ThisWorkbook.Path & "" & k & ".xlsx"
- wb.Close
- End If
- Next
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- MsgBox "拆分完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
- End Sub
复制代码
|
|