>Does anyone have an example how to insert sum() function in excel spreadsheet in code? I'm building the spreadsheet in code, and at the end, I want to sum each column.
You can get the syntax for almost any Excel command with the Record Macro feature. Record the macro, and then look at the generated code. See also my introduction to Excel Automation - Universal Thread Magazine, September 2002.
In the case of the sum, this gives you a syntax in row/column format, which is a little different from the one Sergey suggested. I got accustomed to this syntax, and prefer it, because both rows and columns are referred to by numbers, which is easier (in the case of columns) than letters. (What is the next column after column AC? After column AZ? Easy for a human, but tricky to program.)
The main problem with the sum is usually to get the number of rows, which is often variable.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)