Search code examples
vbamsgbox

Merge multiple MsgBox into one


I am trying to merge multiple MsgBoxs into one, but i have no luck. If you have any ideea, please help. This is my VBA:

  If Worksheets("XXX").Range("D13") > 0 Then

MsgBox ("ATENTION!" & vbCrLf & "OLD = ") & Worksheets("XXX").Range("D13") & " PCS !"
End If

If Worksheets("XXX").Range("E13") > 0 Then
MsgBox ("ATENTION!" & vbCrLf & "REQUEST = ") & Worksheets("XXX").Range("E13") & " PCS !"
End If

Thank you!


Solution

  • You want to show both messages in one box? Like this?

    Dim msg As String
    If Worksheets("XXX").Range("D13") > 0 Then
        msg = "ATENTION!" & vbCrLf & "OLD = " & Worksheets("XXX").Range("D13") & " PCS !"
    End If
    
    If Worksheets("XXX").Range("E13") > 0 Then
        msg = msg & vbCrLf & "ATENTION!" & vbCrLf & "REQUEST = " & Worksheets("XXX").Range("E13") & " PCS !"
    End If
    MsgBox msg