2011-12-23 72 views
2

Here's the problem.当只有一个小计分组行:VBA Excel中插入的大纲级别3的行进来的大纲级别2

  • 插入的行不会在正确的outlinelevel进来了。
  • 小计不会自动包含插入的单元格。

及这里的插入的行(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 

我想这是一个简单的问题,如果你知道这一点。我只是不知道它,让我非常沮丧。祝你有个愉快的第一篇文章,祝你节日快乐。

回答

1

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

从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 

祝你好运。

+0

我的歉意,我不知道任何人回答,直到我今天回来,关于另一个问题。非常感谢,我会在这个新的绊脚石之后尝试。回应圣诞节前夕无所谓....谢谢。 – Bippy 2012-01-07 22:05:45

+0

我看起来并不是那么狂热。我们所有的孩子都和伴侣的父母一起过圣诞节。所以对我们来说,真正忙碌的一天直到28日才推迟。 – 2012-01-08 12:23:20