macro errors

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Macro Errors

Macro Errors

resolvedResolved · High Priority · Version 2003

Graham has attended:
Excel Intermediate course
Excel Advanced course

Macro Errors

I have recorded a macro which pastes data into a preselected row. Before running this macro the user has to have copied data from a seperate sheet. When the macro is run with data in the clipboard, it works correctly and pastes the data. If there is no data in the clipboard the macro returns the normal "Microsoft Visual Basic" error box showing Run-time error '1004': and the button choices of "End" and "Run". Is there a simple way of adding a personalised Error, e.g. ERROR: No data in Clipboard

Many thanks
Graham Warren
0777 5757 389

Edited on Mon 6 Oct 2008, 11:08

RE: Macro Errors

Hi Graham

Thank you for your question. You need to create an error handler

Go to your macro code. Immediately below the first line which will say SUB and then the Macro's name, type

On Error, go to errorhandler


Then on the line immediately above the final line, end sub type the following

exit sub
ErrorHandler:
If err.number = 1004 then

msgbox "There is No data in the clipboard"

else

msxbox "Unexpected Error "& err.number

end if


This will solve this problem for you

Regards

Stephen

 

Training courses

 

Training information:

See also:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Get to the end of the used range

What

View all Excel hints and tips


Server loaded in 0.08 secs.