Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How do I perform a certain function if VBA throws up an error?


IF the below code throws up an error (i.e. lookup_value, a parameter
passed into the sub/function is not contained in the worksheet) THEN
(do something)...

ELSE (do something else)....

END IF

I'm sure its trivial, any help appreciated.



Cells.Find(What:=lookup_value, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Many thanks

Matt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default How do I perform a certain function if VBA throws up an error?


On Error Resume Next ' turns off normal error trapping
' your code that may fail here
If Err.Number then ' Err.Number is error code. 0 = no error
' error handling here (Err.Description contains error message)
End if
On Error Goto 0 ' reset normal error trapping


Matt wrote:
IF the below code throws up an error (i.e. lookup_value, a parameter
passed into the sub/function is not contained in the worksheet) THEN
(do something)...

ELSE (do something else)....

END IF

I'm sure its trivial, any help appreciated.



Cells.Find(What:=lookup_value, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

Many thanks

Matt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How do I perform a certain function if VBA throws up an error?

perfect, knew it would be simple.

many thanks

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
How do in perform trial and error method in excel? Raajesh Excel Worksheet Functions 1 October 3rd 08 10:32 AM
perform 1 function, stop, perform different function nastech Excel Discussion (Misc queries) 0 August 22nd 06 12:21 PM
Excel 2000 - Excel 2003 now throws 'runtime error' Ralph L Excel Programming 3 April 10th 06 05:20 AM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
Format statement no longer throws an error PF[_2_] Excel Programming 6 March 4th 04 02:44 PM


All times are GMT +1. The time now is 09:51 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"