Results 1 to 5 of 5

Thread: [RESOLVED] Range.find

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Location
    Arlington, TX
    Posts
    60

    Resolved [RESOLVED] Range.find

    Ok, right now I have a range.find method to try to...well...find some data...but it keeps giving me an error when the data I'm searching for isn't there.

    VB Code:
    1. If IsNull(Cells.Find(What:=Worksheets("Open Orders").Cells(i, 1), After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    2.     xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    3.     , SearchFormat:=False).Activate) = True Then
    4.            
    5.     Sheets("Open Orders").Cells(i, "N") = 0
    6. Else
    7.     Sheets("Open Orders").Cells(i, "N") = ActiveCell.Offset(0, 34)
    8. End If
    Now, I'm assuming I'll have to change that IsNull to something else to be able to catch it, but I'm not sure what I have to change it to, or if that's even the right direction to go in.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Range.find

    empty cells don't return null, cells won't accept null
    they are = vbnullstring or ""
    VB Code:
    1. If Sheets("Open Orders").Cells(i, 1) = "" Then
    2.     Sheets("Open Orders").Cells(i, "N") = 0
    3. Else
    4.     Sheets("Open Orders").Cells(i, "N") = ActiveCell.Offset(0, 34)
    5. End If

    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2005
    Location
    Arlington, TX
    Posts
    60

    Re: Range.find

    Hmm...that's not quite what I'm trying to do. The Cells(i, 1) holds a value that I'm trying to find in a different worksheet. The only problem is, occasionally there's a value that's not in the worksheet that I'm searching, and when that happens, the Range.find function throws an error...91 I think. What I'd ultimately like to do is to put a zero in the Cells(i, "N") if the error occurs, meaning that there was no match found.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Range.find

    trap the error with an error handler?
    before where you expect the error put
    VB Code:
    1. on error goto onerror
    straight above end sub put
    VB Code:
    1. exit sub
    2. onerror:
    3. if error.number = 91 then cells(i,"N")=0

    pete

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2005
    Location
    Arlington, TX
    Posts
    60

    Re: Range.find

    That makes sense. I'll try it out tomorrow and see if I can get it to work. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width