|
发表于 2014-2-9 19:00
|
显示全部楼层
本楼为最佳答案
- Dim Arr, i&, j&, aa, h, ks, js, n&, k
- Sub lqxs()
- Dim d, t
- Set d = CreateObject("Scripting.Dictionary")
- Sheet1.Activate
- With [d:d]
- .ClearContents
- .UnMerge
- .Interior.ColorIndex = xlNone
- End With
- Arr = [e3].CurrentRegion
- [d3].Resize(UBound(Arr), 1).Borders.LineStyle = 1
- For i = 2 To UBound(Arr)
- d(Arr(i, 4)) = d(Arr(i, 4)) & i & ","
- Next
- k = d.keys: t = d.items
- For i = 0 To UBound(k)
- t(i) = Left(t(i), Len(t(i)) - 1): n = 0
- If InStr(t(i), ",") Then
- aa = Split(t(i), ",")
- ks = aa(0) + 2: h = 0
- For j = 0 To UBound(aa)
- h = h + Arr(aa(j), 1)
- If Abs(h - 1) < 0.1 Then
- js = aa(j) + 2
- Call yy
- If j + 1 <= UBound(aa) Then ks = aa(j + 1) + 2
- ElseIf h > 1 Then
- js = aa(j - 1) + 2
- h = h - Arr(aa(j), 1)
- Call yy
- If j + 1 <= UBound(aa) Then ks = aa(j) + 2: h = Arr(aa(j), 1)
- Else
- GoTo 100
- End If
- 100:
- Next
- Else
- End If
- Next
- If h <> 0 Then js = UBound(Arr) + 2: Call yy
- End Sub
- Sub yy()
- Dim ys
- If h > 1 Then
- ys = 6
- ElseIf h < 1 Then
- ys = 4
- End If
- With Cells(ks, 4).Resize(js - ks + 1, 1)
- .Merge
- n = n + 1
- .Value = Arr(ks - 2, 4) & Format(n, "00")
- .Interior.ColorIndex = ys: h = 0
- End With
- End Sub
复制代码 看看这个吧 |
|