cyberkiwi helped me with this question (31273869) , and it works perfectly, but now it becomes more complicated.
I need to group by multiple columns, please see attached screen shot.
I build my data with a query see image ( Data generated )
If you look at my code I loop threw all the data, if I found a entry that says TL then I know I must do a sum of the range, but I am not sure how to do the sum for the entrire group.
with ADOQuery do
while not eof do
Sheet.Cells(row,1) := trim(FieldByName('Id').AsString);
Sheet.Cells(row,2) := trim(FieldByName('System').AsString);
Range := Sheet.Range['C'+IntToStr(row)];
Range.Formula := FormatFloat('#0.00',FieldByName('amount').AsFloat);
//do some for Line total
if trim(FieldByname('RecType').AsString) = 'TL' then
Range.Formula := Format('=SUM(C%d:C%d)', [lastwrittenrow+1, row-1]);
lastwrittenrow := row;
//code for group total ??????????????????????