'Sum value of textboxes in an excel cell
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"
Solution 1:[1]
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);
}
Solution 2:[2]
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | N.A |
| Solution 2 | Haim Katz |
