Raj De Inno Raj De Inno - 1 year ago 115
C# Question

how to calculate total Sum in Excel

I am producing last report for my venture. I need to ascertain the Sum of aggregate cells in my excel sheet. I have done the accompanying code. Be that as it may, its not computing the qualities.. Here is my code:

Worksheet.Cells[20, 16].Formula =
"Sum(" + Worksheet.Cells[6, 16].Value +
":" + Worksheet.Cells[rowIndex, 16].Value + ")";

I need to figure the Cell No 16's Sum esteem and I will show it into Cells[20,16]. Its not working. Anybody help me to settle this?

Answer Source

Change the two occurrences of .Value in your code to .Address.

Update ... and add a = before the Sum:

Worksheet.Cells[20, 16].Formula =
        "=Sum(" + Worksheet.Cells[6, 16].Address + 
        ":" + Worksheet.Cells[rowIndex, 16].Address + ")";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download