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

macro errors

ResolvedVersion 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

Excel tip:

Copying Values Without Formulas in Excel 2010

If you want to copy the contents of a cell but don't want to copy the formula with it then use the following simple method:

Press Ctrl+C to copy the values in the cell. On the Home tab, click Paste and then click Paste Values.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.