2

これが問題です。小計グループに行が 1 つしかない場合:

  • 挿入された行は、正しいアウトライン レベルにはなりません。
  • 小計には、挿入されたセルが自動的に含まれません。

行を挿入するコードは次のとおりです (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

知っていれば簡単な問題だと思います。私はそれを知らないだけで、かなりイライラしています。私への最初の投稿、そしてあなたへの幸せな休日。

4

1 に答える 1

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

幸運を祈ります。

于 2011-12-24T09:50:22.473 に答える