individual subtotals


Posted by andrew on June 29, 2001 2:56 PM

I have a problem
i have written a macro
that starts with a complete excel sheet
sorts and pastes each seperate name no matter how many times it occurs
I have then inserted a space between each section on the sheet
How do i insert a subtotal for each seperate column of data

example of what i need


column a column b

data
data
data
subtotal data
data1
data1
subtotal data1
data2
data2
data2
data2
data2
subtotal data2

I need this to work no matter how many rows of each section of data there are.
please help me

Posted by mseyf on July 02, 2001 1:24 PM

if your macro is inserting the blank rows, grab the row number of the blank row, then insert a formula based on the previous blank row and the current position of active cell.
if you were trying to sum up column A, and you saved the row number of the previous inserted blank row as intOldRow, you could use a line of code in your macro like:

ActiveCell.Formula = "=subtotal(9,a" & intOldRow - 1 & ":a" & ActiveCell.Row - 1 & ")"

to insert a subtotal.

HTH

-Mark



Posted by mseyf on July 02, 2001 1:41 PM

formula should be:

ActiveCell.Formula = "=subtotal(9,a" & intOldRow + 1 & ":a" & ActiveCell.Row - 1 & ")"