|
代码如下,仅供参考。。。
Sub test()
arr = Sheet1.UsedRange
ReDim brr(1 To UBound(arr), 1 To 6)
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If InStr(arr(i, 1), "工程名称") Then
s = Split(arr(i, 1), "工程名称:")(1)
If InStr(s, "【") Then
ss = Split(s, "【")(0)
sss = Replace(Split(s, "【")(1), "】", "")
If Not d.exists(ss) Then
Set d(ss) = CreateObject("scripting.dictionary")
d(ss)(sss) = ""
n = n + 1
brr(n, 1) = WorksheetFunction.Text(d.Count, "[dbnum1]")
brr(n, 2) = ss
n = n + 1
brr(n, 1) = d(ss).Count
brr(n, 2) = sss
End If
ElseIf Not d(ss).exists(s) Then
d(ss)(s) = ""
n = n + 1
brr(n, 1) = d(ss).Count
brr(n, 2) = s
End If
ElseIf IsNumeric(arr(i, 1)) And Len(arr(i, 1)) <> 0 Then
n = n + 1
brr(n, 1) = d(ss).Count & "." & arr(i, 1)
brr(n, 2) = arr(i, 3)
brr(n, 3) = arr(i, 5)
brr(n, 4) = arr(i, 6)
brr(n, 5) = arr(i, 7)
brr(n, 6) = arr(i, 8)
End If
Next
Set d = Nothing
With Sheet3
.UsedRange.Clear
.[a1].Resize(, 6) = [{"序号","项目名称","计量单位","工程量","综合单价","合价"}]
.[a2].Resize(n, 6) = brr
With .UsedRange
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter
.Columns.AutoFit
End With
.Activate
End With
Beep
End Sub
|
|