ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need some VB script, please (https://www.excelbanter.com/excel-programming/375948-need-some-vbulletin-script-please.html)

rlee1999

Need some VB script, please
 
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


Allllen

Need some VB script, please
 
1) make sure each column has a title (column F will be called class)
2) sort by column F (class) ascending
3) use data subtotals
at each change in Class
use function SUM
apply to columns AI (dollars)

then 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

--
Allllen


"rlee1999" wrote:

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


Bob Phillips

Need some VB script, please
 
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)

"rlee1999" wrote in message
...
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





All times are GMT +1. The time now is 09:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com