2016-06-22 72 views
0

如何創建一個消息框,顯示所有的必填字段尚未填寫的列表VBA消息框。與失敗的檢查

我使用上有一個自動過濾器(表「Table11」)只顯示失敗的檢查。

我想將它們翻譯成一個消息框,顯示銷售代理嘗試創建合同的時間。

表如下佈局:

enter image description here

+0

你到目前爲止嘗試了什麼? –

+0

老實說,我還沒有嘗試過任何東西,因爲我不知道從哪裏開始,我能想到的最好的是'MsgBox'請填寫以下必填字段:「&vbNewLine&」Customer Name「'但這不會' t遍歷列表並添加每個項目,直到找到空白單元格然後停止 –

+0

從[documentation](https://msdn.microsoft.com/en-us/library/office/gg264383.aspx)開始。您可以通過將[for ... next](https://msdn.microsoft.com/en-us/library/office/gg251601.aspx)與[MsgBox](https://msdn.microsoft.com/zh-cn/ .COM/EN-US /圖書館/辦公室/ gg251821.aspx)。 –

回答

0

這是假設CHECK意味着有一個問題

Sub ErrorMessage() 
Dim strErrMsg As String 
Dim cell As Range 
If Application.CountIf(-yourfilteredrangehere-), "CHECK") = 0 Then Exit Sub 
'no problems to output 
For Each cell In Range(-yourfilteredrangehere-) 
    'next line assumes checkitem in previous column, change if not 
    If cell = "check" Then strErrMsg = strErrMsg & "Please check " & cell.Offset(0, -1) & vbCrLf 
Next cell 
MsgBox strErrMsg 
End Sub 
0

下面的示例經過Table11,並創建「查詢」所有那些帶有標註的列表,然後顯示一條消息,如果有項目。

Public Sub Sample() 
Dim LngCounter As Long 
Dim Tbl   As Excel.Range 
Dim StrMsg  As String 

Set Tbl = ThisWorkbook.Worksheets("Sheet1").Range("Table11") 
    For LngCounter = 2 To Tbl.Rows.Count 
     If Trim(UCase(Tbl.Cells(LngCounter, 2))) = "CHECK" Then 
      StrMsg = StrMsg & Tbl.Cells(LngCounter, 1) & vbNewLine 
     End If 
    Next 
Set Tbl = Nothing 

If StrMsg <> "" Then 
    MsgBox "The following items need attention before continuing: - " & vbNewLine & vbNewLine & StrMsg, vbOKOnly + vbExclamation, "Data Validation" 
End If 

End Sub