VBA Excel 在大纲级别 3 上插入行进入大纲级别 2

发布于 2024-12-22 17:11:33 字数 1024 浏览 3 评论 0原文

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

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

这是插入行的代码(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

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

Here's the problem. When there is only one row in a subtotal grouping:

  • the inserted row doesn't come in at the right outlinelevel.
  • the subtotal doesn't automatically include the inserted cell.

And here's the code that inserts the row (i is defined earlier):

           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

I imagine this is an easy problem if you know it. I just don't know it and it's gotten me pretty frustrated. Happy first post to me and happy holidays to you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城孤痞 2024-12-29 17:11:33

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

来自 MS 帮助的关于概述工作表

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

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

             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

祝你好运。

This is a guess but I think it is worth a try.

From MS Help's About outlining a worksheet

  • "Data to be outlined should be in range, where each column has a label in the first row and contains similar facts, and there are no blank rows or columns [my highlighting] within the range."

At the time you set the outline, the sub-total row is blank so cannot be part of the range. Try:

             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

Best of luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文