2

这就是问题所在。当小计分组中只有一行时:

  • 插入的行没有进入正确的大纲级别。
  • 小计不会自动包含插入的单元格。

这是插入行的代码(我之前定义过):

           For j = 2 To lEndRow * (1.5)
                If InStr(Cells(j, i), "Total") Then
                    Cells(j - 1, i).EntireRow.Insert
                    With Cells(j - 1, i)
                        .EntireRow.Font.ColorIndex = 3
                        .EntireRow.Interior.ColorIndex = 2
                    End With
                    Cells(j - 1, i).EntireRow.OutlineLevel = 2 ' This didn't work,
                         ' it puts all the inserted rows at 2 but doesn't group it
                         ' the subtotal.
                    Cells(j - 1, i + 8) = "1% Discount within terms"
                    Cells(j - 1, i + 24).FormulaR1C1 = "=Round((R[2]C[-8])*(.01),2)"
                    j = j + 1
                End If
            Next

我想这是一个简单的问题,如果你知道的话。我只是不知道,这让我很沮丧。祝我第一次发帖快乐,祝你节日快乐。

4

1 回答 1

1

这是一个猜测,但我认为值得一试。

来自 MS Help 的关于概述工作表

  • “要概述的数据应该在范围内,其中每一列在第一行都有一个标签并包含类似的事实,并且范围内没有空白行或列[我的突出显示]。”

在您设置大纲时,小计行是空白的,因此不能成为范围的一部分。尝试:

             Cells(j - 1, i + 8) = "1% Discount within terms"
             Cells(j - 1, i + 24).FormulaR1C1 = "=Round((R[2]C[-8])*(.01),2)"
             Cells(j - 1, i).EntireRow.OutlineLevel = 2

祝你好运。

于 2011-12-24T09:50:22.473 回答