0

I have an application that fills with data an excel template .Template is .xlsm .In template I created vba function called SumByColor when i try to set a cell formula to this function i get this error :

{"Name 'SumByColor' is completely unknown in the current workbook"}

I set formula like this :

sheet.GetRow(rowIndex).GetCell(startPos + 2).SetCellFormula(string.Format("SumByColor($AQ$7,F{0}:AI{0})",rowIndex+1));
user2446025
  • 11
  • 1
  • 2
  • Should you be setting to `"=SumByColor(...)"`? – yu_ominae Aug 01 '14 at 09:30
  • no if Iwrite like this "=SumByColor(...)" i get :{NPOI.SS.Formula.FormulaParseException: The specified formula '=SumByColor($AQ$7,F8:AI8)' starts with an equals sign which is not allowed. – user2446025 Aug 01 '14 at 11:37
  • That's weird. When you don't put the equal it seems to think that `SumByColor` is a range name, and when you use the equal it won't let you. When you say you `have an application`, what type of application are you talking about? And how are you communicating with Excel from your application? – yu_ominae Aug 04 '14 at 00:01

2 Answers2

1

Have you tried setting the cell Type as Formula before setting the formula for cell. For Ex:

XSSFRow row = (XSSFRow)sheet.GetRow(i);
ICell cell = row.CreateCell(1);  
cell.SetCellType(CellType.Formula);
cell.SetCellFormula("SUM(B1:B10)");

You can read up more on setting formula and constraints.

Panda
  • 6,955
  • 6
  • 40
  • 55
kumar chandraketu
  • 2,232
  • 2
  • 20
  • 25
0

How are you assigning the formula? Are you trying something like this?

Range("A10") = "=SumByColor($AQ$7,F8:AI8)"
ejlj
  • 175
  • 3