MsgBox problem

Yulyo

Board Regular
Joined
Jul 17, 2017
Messages
94
Hello all,
I have a problem with my VBA, maybe you can help me.


Everything is working fine, but even if XXX!D13 =0, i still recieve an empty message with "ok" button. How can i change the vba, so that in case XXX!D13 is zero, not to have any message.

This is my VBA:




Code:
Dim msg AsString
If Worksheets("XXX").Range("D13")>0Then
msg ="ATENTION!"& vbCrLf &"OLD = "& Worksheets("XXX").Range("D13")&" PCS !"
EndIf


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

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi ,

The problem is that the last line of code :

MsgBox msg

is always executed , whether D13 or E13 are greater than zero or not.

Change that last line of code to :

If msg <> vbNullString Then MsgBox msg
 
Upvote 0
Thank you both for your answers. It's almost working right now.

So if D13 & E13 = 0, i have no message;
If D13 & E13 > 0, i have a message
The only problem is that, for example, if D13=0 and E13=1, the message won't appear at all...
 
Last edited:
Upvote 0
Hi ,

How so ?

Your two IF statements are following one after the other.

For the case that you have posted , because D13 is 0 , msg will remain blank after the first IF statement has executed.

However , because E13 is greater than 0 , the IF statement will ensure that msg now contains the desired message string , and this will be displayed by the MsgBox statement.
 
Upvote 0

Forum statistics

Threads
1,215,479
Messages
6,125,041
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top