vba excel 中窗体输入问题

Sub luru()
Dim TempMsgBox As VbMsgBoxResult
If UserForm1.TextBox1.Text = "" Or UserForm1.TextBox2.Text = "" Or UserForm1.TextBox3.Text = "" Or UserForm1.TextBox4.Text = "" Or _
UserForm1.TextBox5.Text = "" Or UserForm1.TextBox6.Text = "" Or UserForm1.TextBox7.Text = "" Or UserForm1.TextBox8.Text = "" Or _
UserForm1.TextBox9.Text = "" Then
TempMsgBox = MsgBox("请输入完整的数据!", vkOkOnly, "提示")
End If
invest = UserForm1.TextBox1.Text
year1 = UserForm1.TextBox2.Text
revenue = UserForm1.TextBox3.Text
cost = UserForm1.TextBox4.Text
year2 = UserForm1.TextBox5.Text
depreciation = UserForm1.TextBox6.Text
interest = UserForm1.TextBox7.Text
tax = UserForm1.TextBox8.Text
discount = UserForm1.TextBox9.Text
Range("A1").Select
Selection.Offset(0, 0) = invest
Selection.Offset(1, 0) = year1
Selection.Offset(2, year1 - 1) = revenue
Selection.Offset(3, year1 - 1) = cost
Selection.Offset(4, 0) = year2
Selection.Offset(5, year2 - 1) = depreciation
Selection.Offset(6, 0) = interest
Selection.Offset(7, 0) = tax
Selection.Offset(8, 0) = discount
Call Init
End Sub
为什么说要求对象有问题,会报错

第1个回答  2013-03-15
你点击调试:
看错误在哪一行
一般有几种情况:
1.格式错误
2.引用的对象不存在追问

错误在第一个If 就开始了,运行后会说运行时错误424,要求对象,所以我不知道是什么问题,求解答呀,谢谢

追答

UserForm1.TextBox1.Text
是不是
UserForm1.TextBox1.value

本回答被网友采纳
第2个回答  2013-03-15
哪一句报错?你可以按F8看是哪句出错了追问

我按F8第一次Sub luru()显示黄色,第二次是If显示,不知道问题在哪

追答

你把文件发sm100e@qq.com
你的窗体名称搞错了,
Sub luru()
Dim TempMsgBox As VbMsgBoxResult
With npv
If .TextBox1.Text = "" Or .TextBox2.Text = "" Or .TextBox3.Text = "" Or .TextBox4.Text = "" Or _
.TextBox5.Text = "" Or .TextBox6.Text = "" Or .TextBox7.Text = "" Or .TextBox8.Text = "" Or .TextBox9.Text = "" Then
TempMsgBox = MsgBox("请输入完整的数据!", vkOkOnly, "提示")
End
End If
invest = .TextBox1.Text
year1 = .TextBox2.Text
revenue = .TextBox3.Text
cost = .TextBox4.Text
year2 = .TextBox5.Text
depreciation = .TextBox6.Text
interest = .TextBox7.Text
tax = .TextBox8.Text
discount = .TextBox9.Text
End With
Range("A1").Select
Selection.Offset(0, 0) = invest
Selection.Offset(1, 0) = year1
Selection.Offset(2, year1 - 1) = revenue
Selection.Offset(3, year1 - 1) = cost
Selection.Offset(4, 0) = year2
Selection.Offset(5, year2 - 1) = depreciation
Selection.Offset(6, 0) = interest
Selection.Offset(7, 0) = tax
Selection.Offset(8, 0) = discount
Call Init
End Sub
这样就行了,即把你的代码中所有的UserForm1替换成npv即可

第3个回答  2013-03-15
留下QQ联系方式,我来帮你解决。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网