首页 > 解决方案 > 在特定条件下在用户窗体中显示消息框

问题描述

在此处输入图像描述我有 sheet1 包含 3 列项目、品牌、数量和 userform 在 sheet1 中包含与 textbox1、2、3 相同的元素当我在 userform 中写入数据时我会编写代码向我显示警告消息“你不能添加这个品牌只有 3 或 4...等可用”。

有关显示消息的更多解释取决于 textbox3 示例 sheet1 中的第 3 列包含数量,当我填写 textbox3 多于第 3 列时,然后显示消息。

标签: excelvba

解决方案


我仍然不完全确定你的意思,但试试这样的

Private Sub TextBox1_AfterUpdate()

'assuming this is the range where the relevant values are'
MaxValu = Application.WorksheetFunction.max(Sheets("Sheet1").Range("C3:C5"))

'change the text box value to an integer'
TxtBoxValu = CInt(Me.TextBox1.Value)

If TxtBoxValu > MaxValu Then MsgBox "this value is too high, the maximum you can 
pick is " & MaxValu 


End Sub

推荐阅读