short message box

G

George

Hi, all:

I have a worksheet which requires cell A1 value must be = 0. My macro
will pop up an ERROR message if this value is > 0. The user must fix
this value to 0 before other coding was compiled. How to fix this?

here is my code:

Sub Test()

if worksheets("Sheet1").Range("A1").value > 0 Then

msgbox"This value must be 0. Please fix before proceeding",vbcritical,
"Must fix the value before proceeding"

End if

Other coding ..........

End Sub
 
P

PCLIVE

Not sure what you want to do...but if you want the code to stop running so
that the cell can be fixed, then maybe this:

Sub Test()

if worksheets("Sheet1").Range("A1").value > 0 _
Then
msgbox"This value must be 0. Please fix before
proceeding",vbcritical, "Must fix the value before proceeding"
end
Else
End if

Other coding ..........

End Sub


You might also change the if line of code to be "<>0"

HTH,
Paul
 
G

Guest

Something like this:

Sub Test()

if worksheets("Sheet1").Range("A1").value <> 0 Then

msgbox "This value must be 0. Please fix before proceeding",vbcritical,
"Must fix the value before proceeding"
Exit Sub
End if

'Other coding ..........

End Sub
 
G

Gary Keramidas

i must be missing something, because if you test the value A1 and it is >0, why
don't you just set it to 0?
 
G

George

Hi, Paul and Wigi:

Both of your ways are perfect! They are exactly what I want. Why
should I set A1 value <>0? Thank you so much for your help!


Hi, Gary:

Good question. The reason why I need to set it up as zero is because
that is the condition to pop up the message.

Thanks for your interest!

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top