Need some VB script, please

R

rlee1999

I have 22 different classes in Column F, each class may have 1-25 item rows.
I need to locate the last row of each class and insert a row below it (22 new
rows inserted throughout the sheet). Then I need it to sum the dollar amounts
located in Column AI in the new row for all of the items in each class.

I hope you can help.

Thank you,

~Robert
 
A

Allllen

1) make sure each column has a title (column F will be called class)
2) sort by column F (class) ascending
3) use data > subtotalsthen hit OK

Excel adds the subtotals and extra rows for you.
You can get a group level summary by clicking 1,2,3 on the left
 
B

Bob Phillips

Sub SumClasses()
Dim iLastRow As Long
Dim i As Long
Dim tmp

iLastRow = Cells(Rows.Count, "F").End(xlUp).Row
tmp = ""
For i = iLastRow To 1 Step -1
If Cells(i, "F").Value <> tmp Then
tmp = Cells(i, "F").Value
Rows(i + 1).Insert
Cells(i + 1, "F").Formula = "=SUMIF(F1:F" & i & ",""" & tmp &
""",AI1:AI" & i & ")"
End If
Next i

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top