我目前有此代码
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
For Each myCell In Range("G4:G160")
If (Not IsEmpty(myCell)) And myCell.Value <> 17521 And myCell.Value <> "" Then
DisplayUserForm
Exit Sub
End If
Next myCell
End Sub
并在我的用户表单中使用它
Sub DisplayUserForm()
Dim form As New WarningBox
form.LOL.Caption = "INCORRECT!"
form.Show
Set form = Nothing
结束子
为了使它出现而不是msgbox来提醒任何输入数据的人,我必须做的其他事情就是显示“ INCORRECT!”。粗体并被红色包围。请查看下面我要显示的图像
请执行以下步骤:
UserForm
选项下选择Insert
,插入新表单。key to open the
属性”窗口。Properties
窗口上,表单的默认名称为UserForm1
。根据需要将其更改为任何新值(例如WarningBox)ToolBox
窗口中,将Label
拖放到窗体上,并调整其大小,字体,字体颜色以及Properties
窗口中存在的所有其他属性。请将标签重命名为message
。稍后在调用要显示的表单时,我将使用此名称。CommandButton
添加到表单中,并将其名称更改为例如okButton
,然后根据需要调整其他属性。Private Sub okButton_Click()
'Close the form
Unload Me
End Sub
DisplayUserForm()
子:Sub DisplayUserForm()
Dim form As New warningBox
form.message.Caption = "write your message here"
form.Show
Set form = Nothing
End Sub
您将根据需要完成所有操作!