首页 > 解决方案 > Change the grouping level of a newly inserted row (Excel)

问题描述

So, I have 3 levels of groupings in my excel sheet, and I am trying to add a row at the bottom of the sheet. I want the new row to extend the level 2 (and level 1) groupings but not the level 3, but I don't know how to do that. I would really appreciate it if any of you could help me.

Link to image for clarification -> https://imgur.com/8ucVHWQ Note: The new row is added above 16th row. 2nd image -> https://imgur.com/a/3w3huh0

Thank you in advance.

标签: excelvba

解决方案


试试这个子:

Public Sub InsertRowLevel2()
    ActiveCell.EntireRow.Insert
    ActiveCell.EntireRow.OutlineLevel = 3
End Sub

它将插入一个新行并将其设为 2 级。

但是,这是一个非常具体的功能,设计整个算法会是一个更好的主意,例如,您不应该依赖 ActiveCell,除非这将从命令按钮的事件处理程序中调用(并且您检查 ActiveCell 是一个您期望的,而不是在不同的工作簿中)。


推荐阅读