LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Sum of each row.

You asked for subtotal of each row, but give an example for the result of
totaling each column. Your problem needs clarification. However, here is
something to play with.

Each Row:
lastRow = ActiveSheet.Cells(Rows.Count).End(xlUp).Row
For i = 1 To lastRow
Range("D" & i) = WorksheetFunction. _
Sum(Range("A" & i & ":C" & i))
Next

Each Column:
lastRow = ActiveSheet.Cells(Rows.Count).End(xlUp).Row
For i = 1 To 3
With ActiveSheet
.Cells(lastRow + 1, i) = _
WorksheetFunction.Sum(Range(.Cells(2, i), .Cells(lastRow, i)))
End With
Next




"Rasheed" wrote:

Hi All,

i have created one xls file using c# Excel =
Microsoft.Office.Interop.Excel. DLL
and i have the data like below


A B C
1 100 20 30
2 101 20 31
3 102 20 35
4 103 20 35
5 104 20 32


I need to do subtotal of each row. please help me out how to do ?


result will be like below


-------------------------------------------------------------
GrandTotal 510 100 163
-------------------------------------------------------------


i am using the below function but it gives only one row total only.
but i want 3 rows Grand Total individually like above.

oWSheet.get_Range("A1" , "D5" )).Subtotal(1,
Excel.XlConsolidationFunction.xlSum, Type.Missing,
(object)true, (object)true, Excel.XlSummaryRow.xlSummaryBelow);

thanks in advance.

regards
Rasheed

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"