【问题标题】:VBA Excel Inserting a row on outline level 3 comes in on outline level 2VBA Excel 在大纲级别 3 上插入一行进入大纲级别 2
【发布时间】:2011-12-23 22:00:52
【问题描述】:

Here's the problem.小计分组只有一行时:

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

下面是插入行的代码(i 之前定义过):

           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

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

【问题讨论】:

    标签: insert excel outline vba


    【解决方案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
    

    祝你好运。

    【讨论】:

    • 抱歉,直到今天回来,我才知道有人回复,关于另一个问题。非常感谢,我会在这个新的绊脚石之后尝试一下。平安夜的回应仍然如此......谢谢。
    • 我并不像看起来那样狂热。我们所有的孩子都和他们伴侣的父母一起过圣诞节。所以对我们来说,真正忙碌的一天被推迟到了 28 日。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2016-06-09
    • 2022-10-15
    • 1970-01-01
    相关资源
    最近更新 更多