Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Error trap with object variable problem

Hello, I have a macro with a series of different error traps which are set
at appropriate points in a loop. The errors I want to trap are when the Find
method doesn't find what it's looking for. The code I use looks like this:

' Find the Oracle RefNo & Assignment from the EmpNo sheet
On Error GoTo ErrorTrap
EmpNoRow =
EmpNoSheet.Columns("C:C").Find(What:=InDataSheet.C ells(InDataRow, 3)).Row

there is a value in the specified cell, and all of the object variables are
appropriately set. The code works fine when the value is found, but when it
is missing it displays the Debug dialog box (which is exacly what I want to
trap) .

It says: Run time Error 91 - Object variable or with block not set.

Strangely though, sometimes my error traps do work with identical code. Any
ideas?

Thanks




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error trap with object variable problem

Hello Mike H, :)

Please use a range type variable instead of EmpNoRow. It make
trappling easy.
When the value is found, a variable rngFound has the range, if th
value is not found a variable rngFound has Nothing.


Code
-------------------

Dim rngFound As Range
Set rngFound = EmpNoSheet.Columns("C:C").Find(What:=InDataSheet.C ells(InDataRow, 3))

If rngFound Is Nothing Then
'NOT FOUND
GoTo ErrorTrap ' As you like
Else
'FOUND
EmpNoRow = rngFound.Row
End If

-------------------


--
Message posted from http://www.ExcelForum.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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Object variable problem ExcelMonkey[_13_] Excel Programming 4 January 23rd 04 08:39 PM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM
Problem Using an Object Variable in a Class Definition Boxman Excel Programming 2 August 28th 03 03:05 AM


All times are GMT +1. The time now is 11:46 AM.

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

About Us

"It's about Microsoft Excel"