![]() |
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 |
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 |
How do I perform a certain function if VBA throws up an error?
perfect, knew it would be simple.
many thanks |
All times are GMT +1. The time now is 03:11 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com