Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Throwing an error ... on purpose!

Background:
I have been learning to use error handling when coding macros - mostly just
using On Error GoTo statements. I have a subroutine that is called from an
OnError GoTo block. If a certain condition is met (no files were found that
fit my criteria), I want my subroutine to throw an error and return to the
function that called it. This is not a situation that will normally throw an
error, but I need to handle it as if it were an error.

Question:
How do I throw an error? (short of simply putting in a non-valid statement
that I know will cause a real error)

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Throwing an error ... on purpose!

Just add the line

Error 1

Which raises the application defined or object defined error. For different
errors just use the appropriate error number/code.
--
HTH...

Jim Thomlinson


"Sarah B via OfficeKB.com" wrote:

Background:
I have been learning to use error handling when coding macros - mostly just
using On Error GoTo statements. I have a subroutine that is called from an
OnError GoTo block. If a certain condition is met (no files were found that
fit my criteria), I want my subroutine to throw an error and return to the
function that called it. This is not a situation that will normally throw an
error, but I need to handle it as if it were an error.

Question:
How do I throw an error? (short of simply putting in a non-valid statement
that I know will cause a real error)

--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Throwing an error ... on purpose!

Thanks! I've had to rearrange my code and now I don't need to purposely throw
an error. But I will keep this command handy just in case.

--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste Special throwing an error jlclyde Excel Discussion (Misc queries) 0 September 16th 08 03:48 PM
copy and insert throwing error- help in code req dee Excel Discussion (Misc queries) 8 March 6th 08 09:57 PM
aconcat UDF throwing a #NAME error Josh Rogers Excel Worksheet Functions 10 February 14th 08 07:29 PM
Formulas bug or on purpose Pat Excel Discussion (Misc queries) 0 December 5th 07 04:23 PM
Throwing Out top & lower percentages Gary Gonzales Excel Worksheet Functions 2 February 23rd 06 08:30 PM


All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"