|
代码如下。。。
Sub test()
Dim wb As Workbook, sht As Worksheet, sh As Worksheet
Set d = CreateObject("scripting.dictionary")
Set wb = ThisWorkbook
Set sht = wb.Sheets("目标汇总表格式")
ReDim arr(1 To 100000, 1 To 100)
biaoti = [{"序号","规格","窗编号","数量","洞口宽度","洞口高度"}]
n = 1
For i = 1 To UBound(biaoti)
arr(1, i) = biaoti(i)
Next
x = UBound(biaoti)
For Each sh In wb.Sheets
If sh.Name <> sht.Name Then
x = x + 1
arr(1, x) = sh.Name
brr = sh.[a1].CurrentRegion
For i = 3 To UBound(brr)
s = brr(i, 1) & "|" & brr(i, 2) & "|" & brr(i, 3) & "|" & brr(i, 4)
If Len(brr(i, 2)) <> 0 Then
If Not d.exists(s) Then
n = n + 1
d(s) = n
arr(n, 1) = n
arr(n, 2) = brr(i, 2)
arr(n, 3) = brr(i, 1)
arr(n, x) = brr(i, UBound(brr, 2))
arr(n, 5) = brr(i, 3)
arr(n, 6) = brr(i, 4)
Else
m = d(s)
arr(m, x) = brr(i, UBound(brr, 2))
End If
End If
Next
End If
Next
For i = 2 To n
arr(i, x + 1) = "=sum(rc" & (1 + UBound(biaoti)) & ":rc[-1])"
arr(i, 4) = "=sum(rc" & (1 + UBound(biaoti)) & ":rc[" & x - 4 & "])"
Next
arr(1, x + 1) = "小计"
With sht
.UsedRange.Clear
.[a2].Resize(n, x + 1) = arr
.Range("a1", .Cells(1, UBound(biaoti))).Merge
.[a1] = "工程量计算汇总(清单量)"
.Range(.Cells(1, UBound(biaoti) + 1), .Cells(1, x)).Merge
.Cells(1, UBound(biaoti) + 1) = "分部分项清单明细"
.UsedRange.Columns.AutoFit
.UsedRange.Borders.LineStyle = 1
.UsedRange.HorizontalAlignment = xlCenter
End With
Set d = Nothing
Beep
End Sub
|
评分
-
2
查看全部评分
-
|