对不起,前面仨有问题,漏了数据,现在是改版,应该不能跟格式不一样的通用,这个不用新建工作表,直接选中sheet1,右键查看代码,粘贴运行就行了- Sub 数组运行() '15秒
- Worksheets.Add after:=Worksheets("sheet1")
- ActiveSheet.Name = "汇总"
- Set b = Worksheets("汇总")
- Set a = Worksheets(1)
- x = a.UsedRange.Rows.Count
- Dim rng As Range, order As XlOrder, Header As XlYesNoGuess
- Set rng = a.Range(a.Cells(1, 1), a.Cells(x, 3))
- rng.Sort Key1:=a.Range(a.Cells(1, 1), a.Cells(1, 1)), Order1:=xlAscending, Header:=xlYes
- m = 2
- Dim t()
- For i = 2 To x
- ReDim Preserve t(i)
- If a.Cells(i, 1) <> a.Cells(i + 1, 1) And a.Cells(i, 1) <> "" Then
- t(i) = a.Cells(i, 1)
- b.Cells(m, 1) = t(i)
- m = m + 1
- End If
- Next
- Dim rg As Range
- Set rg = a.Range(a.Cells(1, 1), a.Cells(x, 3))
- rg.Sort Key1:=a.Range(a.Cells(1, 2), a.Cells(1, 2)), Order1:=xlAscending, Header:=xlYes
- n = 2
- For j = 2 To x
- If a.Cells(j, 2) <> a.Cells(j + 1, 2) And a.Cells(j, 2) <> "" Then
- b.Cells(1, n) = a.Cells(j, 2)
- b.Cells(1, n + 1) = a.Cells(1, 3)
- n = n + 2
- End If
- Next
- xx = UsedRange.Rows.Count
- y = UsedRange.Columns.Count
- k = b.Range(b.Cells(2, 1), b.Cells(xx, 1))
- kk = b.Range(b.Cells(1, 2), b.Cells(1, y))
- kkk = a.Range(a.Cells(2, 1), a.Cells(x, 3))
- For e = 1 To xx - 1
- For f = 1 To y - 1 Step 2
- For g = 1 To x - 1
- If k(e, 1) = kkk(g, 1) And kk(1, f) = kkk(g, 2) Then
- b.Cells(e + 1, f + 1) = kkk(g, 2)
- b.Cells(e + 1, f + 2) = kkk(g, 3) + b.Cells(e + 1, f + 2)
- End If
- Next
- Next
- Next
- b.Cells(1, 1) = "受理网点"
- End Sub
复制代码 |