?
Solved

VBA process to create readable sub-total blocks in Excel

Posted on 2011-09-28
2
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

800 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