c# excel assign cell value to another worksheet

I am creating an excel workbook by copying a template sheets from another workbook and renaming them.  What I need to do is sum all the created sheets on the first sheet.  When I assign the value to the cell(worksheet.Cells[3, 2]), the cell's value is System.__ComObject.  I don't even set the value of the child cell in code, it is a formula in the template.
This is my code:

                        Worksheet worksheet = ((Worksheet)originalWorkbook.Worksheets["Division Template"]);
                        worksheet.Copy(Missing.Value, previous);
                        worksheet = ((Worksheet)workbook.Worksheets["Division Template"]);
                        worksheet.Activate();
                        worksheet.Name = "Division " + ddlDivision.SelectedItem.Text;

                        while (dReader.Read())
                        {
                            previous = writeSU(dReader["SU_ID"].ToString(), dReader["Name"].ToString(), previous);
                        }

                        int i = 0;
                        foreach (Worksheet sheet in workbook.Worksheets)
                        {
                            if (sheet.Name != "Division " + ddlDivision.SelectedItem.Text)
                            {
                                i++;
                                if (i == 1)
                                    worksheet.Cells[3, 2] = "='" + sheet.Name + "'!B3";
                                else
                                    worksheet.Cells[3, 2] = worksheet.Cells[3, 2].ToString() + "+'" + sheet.Name + "'!B3";

                            }
                        }

        private Worksheet writeSU(string SU_ID, string Employee_Name, Worksheet previous)
        {
            Worksheet result;
            numberSUs++;

            result = ((Worksheet)originalWorkbook.Worksheets["SU Template"]);
            result.Copy(Missing.Value, previous);
            result = ((Worksheet)workbook.Worksheets["SU Template"]);
            result.Activate();
            result.Name = SU_ID + " " + Employee_Name;
...
            return result;
KS_MisAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
BuggyCoderConnect With a Mentor Commented:
to apply formula you need to work with range object. please go through the following MSDN Example, i am sure it will help you:-

http://support.microsoft.com/kb/302084
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.