Solved

VBA process to create readable sub-total blocks in Excel

Posted on 2011-09-28
2
198 Views
Last Modified: 2012-05-12
I have a data array in an Excel sheet. The data is organized by a group code and the rows are sorted by this code.I want to insert a summary block (group averages) after each group. I am familiar with the Subtotal function, but I want to add in 2 blank lines to aid in readability. I am interested in VBA code procedure, so that I may add in more data summarizing fuctions in the future.

Thank you.
Test-Combined-FL-Sept-24.xls
0
Comment
Question by:donohara1
2 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 36717934
This is a pretty workmanlike solution, but I think it does what you want:
Sub x()

Dim r1 As Long, r2 As Long

r1 = 7: r2 = 6

Do While Cells(r1, "C") <> ""
    If Cells(r1, "C") <> Cells(r1 - 1, "C") Then
        Cells(r1, "C").Resize(3).EntireRow.Insert shift:=xlDown
        Cells(r1, "C") = "Average " & Cells(r1 - 1, "C")
        Cells(r1, "D").Resize(, 16).Formula = "=AVERAGE(D" & r2 & ":D" & r1 - 1 & ")"
        r1 = r1 + 4
        r2 = r1 - 1
    Else
        r1 = r1 + 1
    End If
Loop

Cells(r1, "C") = "Average " & Cells(r1 - 1, "C")
Cells(r1, "D").Resize(, 16).Formula = "=AVERAGE(D" & r2 & ":D" & r1 - 1 & ")"

End Sub

Open in new window

0
 

Author Closing Comment

by:donohara1
ID: 36816766
well done and Thanks.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel file that does not ask to be saved before exiting 6 23
VLOOKUP 6 18
Excel - DATEDIF error #NUM 6 26
sumifs excel 2013 3 16
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question