|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("sheet2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("c2:e" & r).ClearContents
- brr = .Range("a2:e" & r)
- For i = 1 To UBound(brr)
- d(brr(i, 1)) = i
- Next
- End With
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:p" & r)
- For i = 1 To UBound(arr)
- xm = Mid(Left(arr(i, 1), InStr(arr(i, 1), "-") - 1), 2)
- If d.exists(xm) Then
- m = d(xm)
- brr(m, 3) = brr(m, 3) + 1
- End If
- If i > 1 Then
- If xm = "TP" Or xm = "TMP1" Or xm = "YTP" Or xm = "YTMP1" Then
- xm1 = "A"
- Else
- xm1 = "B"
- End If
- If Not d1.exists(xm1) Then
- Set d1(xm1) = .Range("a1:p1")
- End If
- Set d1(xm1) = Union(d1(xm1), .Cells(i, 1).Resize(1, 16))
- End If
-
- Next
-
- End With
- With Worksheets("sheet2")
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- For i = 1 To UBound(brr)
- If .Cells(i + 1, 4).MergeArea.Cells(1, 1).Address = .Cells(i + 1, 4).Address Then
- .Cells(i + 1, 4).FormulaR1C1 = "=SUM(R" & i + 1 & "C3:R" & i + .Cells(i + 1, 4).MergeArea.Rows.Count & "C3)"
- End If
- Next
- End With
- Application.SheetsInNewWorkbook = 1
- For Each aa In d1.keys
- Set wb = Workbooks.Add
- With wb
- With .Worksheets(1)
- d1(aa).Copy .Range("a1")
- End With
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa
- .Close False
- End With
- Next
- End Sub
复制代码 |
|