Save using Macro but test to see if an error appears on spreadshee

J

jfaz

I have tests on spreadsheet to see if data is missing and want to save the
spreadsheet using a macro, but first test to see if there is an error
message. I am only a basic user of macro's and use them through record. I
have found out how to put a message box on screen, but want the box to appear
when there is an error, but to save when there are no errors.
 
D

DaveO

You'll need to create a variable to store an error, I'd suggest a Boolean.

--------
Dim blnError as Boolean

blnError = False
--------


Then when your code finds an 'error' add this line straight after

--------
blnError = True
--------

Then at the end of your code, before the save happens, try this

--------
If Not blnError then
{Enter your line of code which saves the data}
Else
MsgBox "Error found, workbook not saved!"
end if
 
Top