How to calculate total amount in Excel

I am producing the latest report for my enterprise. I need to find out the sum of the total cells on my excel sheet. I made the accompanying code. Be that as it may, he does not calculate quality. Here is my code:

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

I need to calculate the value of Cell No. 16 Sum, and I will show it in the cells [20,16]. This does not work. Anyone help me solve this?

+4
source share
1 answer

Change the two occurrences .Valuein your code to .Address.

Update ... and add =before Sum:

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

All Articles