VBA Excel 在大纲级别 3 上插入行进入大纲级别 2
问题所在。 当小计分组中只有一行时:
- 插入的行不会进入正确的大纲级别。
- 小计不会自动包含插入的单元格。
这是插入行的代码(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个猜测,但我认为值得一试。
来自 MS 帮助的关于概述工作表
设置大纲时,小计行为空白,因此不能属于范围的一部分。尝试:
祝你好运。
This is a guess but I think it is worth a try.
From MS Help's About outlining a worksheet
At the time you set the outline, the sub-total row is blank so cannot be part of the range. Try:
Best of luck.