Home > Net >  Sum value of textboxes in an excel cell
Sum value of textboxes in an excel cell

Time:03-26

How do I get the sum of multiple textboxes and put the value in a cell. Is there a way to do it in a function? Like a1 f(x) = "=Textbox1 Textbox2"

CodePudding user response:

Maybe you can make a loop, Then chain the index to the textbox name.

for example:

      int sum=0;
      for(i=1; i< [number of the textbox you have]; i  ){
          sum =Parse.toInt32(Textbox i);               
       }

CodePudding user response:

I don't think the above will work as is. You need to get the textbox object first and then get its value. Something like

Textbox tb;
int sum = 0;
for (i=1; 1<[numberof the textbox you have];i  )
{ tb = (TextBox)(this.Controls("tbItem"   intItemCount.toString()).Text);
 sum  = int.Parse(tb.Text);
}
  • Related