在excel vba中,我有一个窗体,里面有多个文本框,其中一个是计算其它所有文本框中值的总和

我想实现:每当文本框有值输入,那么计算总值的那个文本框就自动把值加上,即时显示出来

第1个回答  2008-09-13
如果你有4 个文本框
TextBox4.Text = Val(TextBox1.Text) + Val(TextBox2.Text)+Val(TextBox3.Text)

那么你可以分别双击TextBox1,TextBox2,TextBox3

在其弹出的窗口中输入
Private Sub TextBox1_Change()
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)+Val(TextBox3.Text)

End Sub

-------------------------------
Private Sub TextBox2_Change()
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)+Val(TextBox3.Text)

End Sub
---------------------------------

Private Sub TextBox3_Change()
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)+Val(TextBox3.Text)

End Sub本回答被提问者采纳
第2个回答  2008-09-13
在窗体上添加所有的文本框
以 TextBox1 为总值
在窗体的代码页上输入下面的代码

Private Sub UserForm_Click()
For Each c In Controls
If c.Name <> "TextBox1" Then v = v + Val(c.Value)
Next
TextBox1.Value = v
End Sub
第3个回答  2019-12-15
私人小组commandbutton2_click()
对于i
=
1到[a65536]。结束(xlup)。行
??cells.find(什么:=
textbox1.text,后::=
activecell)的。激活
??activecell.offset(0,5)。激活
?如果activecell.formular1c1
=
textbox2.text,然后退出对于
??activecell.formular1c1
=
textbox2.text

end
sub
相似回答