Halt A Macro If a Cell Contains a Certain Value

J

John

I'm looking for a macro to be halted if the value in a cells is less than a
certain figure, with a dialog box informing the user appearing

Cell with value is C1 and anything less than 10, should halt the existing
Macro I have, with a Dialog box appearing showing "Halt Who goes there"

Thanks
 
T

Tom Ogilvy

with Worksheets("Sheet3")
if isnumeric(.Range("C1")) then
if .Range("C1").Value < 10 then
msgbox "Halt Who goes there; number less than 10"
Exit sub
end if
Else
msgbox "Halt Who goes there; no number in C1"
exit sub
End if
End With

' continue to process
 
J

John

Thanks for the code Tom


Tom Ogilvy said:
with Worksheets("Sheet3")
if isnumeric(.Range("C1")) then
if .Range("C1").Value < 10 then
msgbox "Halt Who goes there; number less than 10"
Exit sub
end if
Else
msgbox "Halt Who goes there; no number in C1"
exit sub
End if
End With

' continue to process
 
J

John

Tom

I wish to remove the message "msgbox "Halt Who goes there; no number in C1",
just want the one dialog box, but I can't work out my If's from my with's
 
T

Tom Ogilvy

If C1 will always contain a number

with Worksheets("Sheet3")

if .Range("C1").Value < 10 then
msgbox "Halt Who goes there"
Exit sub
end if
End With


--
Regards,
Tom Ogilvy


rg
 
J

John

Thanks Tom, I get totally confused with the number of if, end if, with etc,
no matter what I take-out / remove it always seems to hit debug
 

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