|
- Sub test()
- Dim i As Integer
- Row = Cells(Rows.Count, 1).End(xlUp).Row
- k = 1
- For i = 5 To Row
- If Cells(i, 1) <> Cells(i + 1, 1) Then
- If k = 1 Then
- Cells(i, 7) = "=SUM(B5:B" & Trim(Str(i)) & ")"
- Call merge(5, i)
- Else
- Cells(i, 7) = "=SUM(B" & Trim(Str(k + 1)) & ":B" & Trim(Str(i)) & ")"
- Call merge((k + 1), i)
- End If
- k = i
- End If
- Next i
- End Sub
- Function merge(i As Integer, j As Integer)
- strNanme = "G" & Trim(Str(i)) & ":G" & Trim(Str(j)) & ""
- Range(strNanme).Select
- With Selection
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlBottom
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = False
- End With
- Selection.merge
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- Selection.Borders(xlInsideVertical).LineStyle = xlNone
- Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
- With Selection.Interior
- .Pattern = xlSolid
- .PatternColorIndex = xlAutomatic
- .ThemeColor = xlThemeColorAccent3
- .TintAndShade = 0.399975585192419
- .PatternTintAndShade = 0
- End With
- End Function
复制代码 |
|