PDA

View Full Version : If no error, write the word "ok" to a cell?



doctortt
01-03-2014, 12:32 PM
Can someone please help me with this?I want to do something that says "If the codes under this sub run sucessfully without any error, write the word "ok" on a cell (i.e. A1) in a worksheet called "temp"?I'd appreciate if you could assist.Thanks

Paul_Hossler
01-03-2014, 01:43 PM
seems to be a little round about

Are you asking for a MsgBox to tell the user to enter "OK" in temp's A1?

Are you asking for the running macro to enter OK in temp's A1 before it exits if everything was OK

or a third?

Paul

ashleyuk1984
01-03-2014, 04:13 PM
Maybe do something like...


Sub test()

On Error GoTo bad:


'code goes here
''''
''''
''''
''''


'Good Code
Range("A2").Select


'Bad Code
Range("A4328974238974").Select




'presuming everything ran ok, this would then be the last line of code
Range("A1").Value = "ok"
Exit Sub


'otherwise, if there was an error, this line of code runs.
bad:
Range("A1").Value = "BAD!!!!!"
End Sub

You can test this, by commenting out either the GOOD CODE line above, or the BAD CODE line.
Hope this helps.

sassora
01-04-2014, 02:47 AM
In general, I would be careful here as there could be an error in the procedure that doesn't stop it from running. The "OK" could lead to a false sense of security!

That may be over the top for what you are doing but it's a principle to bear in mind.