|
发表于 2017-4-10 10:40
|
显示全部楼层
本楼为最佳答案
- Sub 生成()
- Dim sh As Worksheet, CopyRng As Range
- Set d = CreateObject("scripting.dictionary")
- Set sh = Worksheets("单位")
- sh.Range("b4,e4,b9:g28,a9") = ""
- sh.Rows("51:1000").Delete
- Set CopyRng = sh.Range("a1:g32")
- With Sheets("分部")
- For i = 5 To .[a65536].End(3).Row Step 50
- lx = .Cells(i, "D") '路线
- If Len(lx) > 0 Then d(lx) = d(lx) & "," & i
- Next
- If d.Count = 0 Then Exit Sub
- For Each lx In d.keys
- r = k * 50 + 1
- If k >= 1 Then CopyRng.Copy sh.Cells(r, 1)
- sh.Cells(r + 3, 2) = lx
- xrr = Split(d(lx), ",")
- n = 0: zgc = ""
- For i = 1 To UBound(xrr)
- r0 = xrr(i)
- gc = .Cells(r0, "E") '工程名称
- zgc = zgc & "-" & gc '把所有工程用“-”联起来
- fs = Application.WorksheetFunction.Average(.Range(.Cells(r0 + 5, 3), .Cells(r0 + 5, 3).End(xlDown))) '平均分
- n = n + 1
- sh.Cells(r + n + 7, 2) = gc
- sh.Cells(r + n + 7, 3) = fs
- Next
- gcrr = Split(zgc, "-")
- sh.Cells(r + 3, 5) = gcrr(1) & "-" & gcrr(UBound(gcrr)) '工程起点--止点
- k = k + 1
- Next
- End With
- End Sub
复制代码 |
|