有人可以就以下內容提供建議嗎
MsgBox 文本是否可以根據滿足的條件顯示多條訊息。
我正在尋找訊息框“沒有足夠的顯示幕庫存!” 如果布林值為真,則自行顯示一條訊息,對于 MsgBox“庫存中的筆記本電腦不足!”也是如此。
但如果兩個布林值都為真,則 Msgbox 將顯示“庫存中的筆記本電腦不足!& 庫存中的顯示幕不足!”
Dim aRow As Long
aRow = Worksheets("MFB Stock").Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row 1
Dim Test As Boolean
Test = Val(TextBox4.Text) > Worksheets("MFB Stock").Cells(aRow, 3).Value
If Test = True Then
MsgBox "Not enough Monitors in stock!"
Exit Sub
End If
'compares cells A2 to textbox 21 - Laptop
Dim Test1 As Boolean
Test1 = Val(TextBox12.Text) > Worksheets("MFB Stock").Cells(aRow, 1).Value
If Test1 = True Then
MsgBox "Not enough Laptops in stock!"
Exit Sub
End If
uj5u.com熱心網友回復:
使用中間變數來收集訊息并用換行符分隔它們:
Dim msg As String
Dim TestMonitor As Boolean
TestMonitor = Val(TextBox4.Text) > Worksheets("MFB Stock").Cells(aRow, 3).Value
If TestMonitor Then msg = msg & IIf(msg = "", "", vbCrLf) & "Not enough Monitors in stock!"
Dim TestLaptop As Boolean
TestLaptop = Val(TextBox12.Text) > Worksheets("MFB Stock").Cells(aRow, 1).Value
If TestLaptop Then msg = msg & IIf(msg = "", "", vbCrLf) & "Not enough Laptops in stock!"
If msg <> "" Then
MsgBox msg, vbExclamation
Exit Sub
End If
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/487661.html
下一篇:使用附加文本拆分單元格值
