2011-12-23 32 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