【发布时间】:2015-05-22 10:42:04
【问题描述】:
我的提交按钮代码如下:
Private Sub CommandButton1_Click()
Sheets("Overall").Activate
With Me
If Len(.ComboBox1.Value) * Len(.TextBox1.Value) * Len(.ComboBox2.Value) * Len(.ComboBox3.Value) * Len(.TextBox2.Value) * Len(.TextBox3.Value) * Len(.ComboBox4.Value) * Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 Then
MsgBox "Please Complete All Fields Before Submit"
Else
eRow = Sheet9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(eRow, 1).Value = ComboBox1.Text
Cells(eRow, 2).Value = TextBox2.Text
Cells(eRow, 3).Value = TextBox3.Text
Cells(eRow, 4).Value = TextBox1.Text
Cells(eRow, 5).Value = ComboBox3.Text
Cells(eRow, 6).Value = TextBox4.Text
Cells(eRow, 7).Value = TextBox5.Text
Cells(eRow, 8).Value = ComboBox4.Text
Cells(eRow, 15).Value = ComboBox6.Text
Cells(eRow, 10).Value = ComboBox5.Text
Cells(eRow, 11).Value = TextBox7.Text
Cells(eRow, 12).Value = TextBox8.Text
Cells(eRow, 13).Value = TextBox6.Text
Cells(eRow, 14).Value = ComboBox2.Text
End If
End With
End Sub
我希望添加一个确认弹出消息框以提醒用户如果在 TextBox8 中键入的值超过 3.0
如果用户选择是,则只将数据存储在excel表中,但如果用户选择否,将显示另一个弹出消息框,通知用户重新输入TextBox8中的值。
我应该在哪里添加 vbYesNo 消息框?
【问题讨论】:
-
在第一个
Else之后添加另一个If块。此外,您应该对Cells(eRow, #).Value做一些事情,因为 Sheet9 可能并不总是处于活动状态。 -
看这里Link
-
我的这篇文章有另一种方法,可能至少在理论上有兴趣:yoursumbuddy.com/userform-event-class-validating-controls