Click here to Skip to main content
14,774,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have generate Excel using c# code.
In this Excel there are 5 sheets
now I want to make formula filed in 1st Sheet.
in this formula I have to use other sheets cell value, not same sheet value.
so how i can do this ?
please any one can give me some idea...

In One sheet how to make formula that I know and i have put this code below.

What I have tried:

((Excel.Range)oExcel.Cells[9, 3]).Formula = "=SUM(C4,C7)";
Updated 15-May-20 23:47pm

1 solution

You need to add the sheetname followed by ! to each cell reference in the formula, for example:
((Excel.Range)oExcel.Cells[9, 3]).Formula = "=SUM(Sheet1!C4,Sheet1!C7)";

Note that if the range is a consecutive set of cells you only need one reference to the sheet thus:
((Excel.Range)oExcel.Cells[9, 3]).Formula = "=SUM(Sheet1!C4:C7)";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900