KP_SoCal
Board Regular
- Joined
- Nov 17, 2009
- Messages
- 116
The block of code below, provided to me by Peter SSs, needs to be modified slightly to accomplish a new task.
Instead of just grouping and offsetting the given values in my range for column A, I need to do something similar for a range in column B with a small exception. The offset target should be at the bottom of the group as opposed to the top of the group. Also the text “Total” should be concatenated to the value of the CLASS group. In the event there is no value for CLASS listed, “Total” should be listed at the bottom of the Null class group.
The screen shot below better illustrates what I’m trying to accomplish. Notice where I have borders inserted as well, and notice how each group is being summed.
Any possible solutions are appreciated more than you could possibly image. Thanks!
KP
Instead of just grouping and offsetting the given values in my range for column A, I need to do something similar for a range in column B with a small exception. The offset target should be at the bottom of the group as opposed to the top of the group. Also the text “Total” should be concatenated to the value of the CLASS group. In the event there is no value for CLASS listed, “Total” should be listed at the bottom of the Null class group.
The screen shot below better illustrates what I’m trying to accomplish. Notice where I have borders inserted as well, and notice how each group is being summed.

Any possible solutions are appreciated more than you could possibly image. Thanks!
KP
Code:
Sub Rearrange()
Dim Aarea As Range, Arange As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Arange = Range("A10", Range("A" & Rows.Count).End(xlUp))
With Arange
.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(1), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
.Offset(2, -1).SpecialCells(xlCellTypeConstants).Offset(, 1).ClearContents
.Offset(, -1).EntireColumn.Delete
.EntireColumn.RemoveSubtotal
End With
For Each Aarea In Arange.SpecialCells(xlCellTypeConstants).Areas
With Aarea
With .Cells(1, 1).Offset(-1)
.Value = .Offset(1).Value
.Font.Bold = True
.EntireRow.Insert
End With
.ClearContents
End With
Next Aarea
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub