+ Reply to Thread
Results 1 to 4 of 4

Stopping errors when a find statement doesn't find!

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164

    Stopping errors when a find statement doesn't find!

    Hi there,
    I have the following code that assumes the value it is looking for is always present:

    [code]
    Range(Columns("A:A").Find("Unplanned Prospects").Offset(0, 0), _
    Columns("A:A").Find("Unplanned Prospects Total").Offset(0, 14)).Select
    Selection.borders(xlDiagonalDown).LineStyle = xlNone
    Selection.borders(xlDiagonalUp).LineStyle = xlNone[code]

    i've just run this and it couldn't find "Unplanned Prospects" so it returned an error.
    how can I get around this?

    thanks in advance,
    Matt

  2. #2
    Harald Staff
    Guest

    Re: Stopping errors when a find statement doesn't find!

    Hi Matt

    See if this makes sense:

    Sub test()
    Dim Found As Range
    On Error Resume Next
    Set Found = Columns("A:A").Find("Unplanned Prospects")
    If Found Is Nothing Then
    MsgBox "No such thing"
    Else
    MsgBox Found.Address
    End If
    End Sub


    HTH. Best wishes Harald

    "matpj" <[email protected]> skrev i melding
    news:[email protected]...
    >
    > Hi there,
    > I have the following code that assumes the value it is looking for is
    > always present:
    >
    >
    > Code:
    > --------------------
    >
    > Range(Columns("A:A").Find("Unplanned Prospects").Offset(0, 0), _
    > Columns("A:A").Find("Unplanned Prospects Total").Offset(0, 14)).Select
    > Selection.borders(xlDiagonalDown).LineStyle = xlNone
    > Selection.borders(xlDiagonalUp).LineStyle = xlNone
    > Code:
    > --------------------
    >
    >
    > i've just run this and it couldn't find "Unplanned Prospects" so it

    returned an error.
    > how can I get around this?
    >
    > thanks in advance,
    > Matt
    >
    >
    > --
    > matpj
    > ------------------------------------------------------------------------
    > matpj's Profile:

    http://www.excelforum.com/member.php...o&userid=21076
    > View this thread: http://www.excelforum.com/showthread...hreadid=504857
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Stopping errors when a find statement doesn't find!

    Dim rng as Range
    set rng = Columns("A:A").Find("Unplanned Prospects")
    if not rng is nothing then
    With rng.Resize(1,15)
    .borders(xlDiagonalDown).LineStyle = xlNone
    .borders(xlDiagonalUp).LineStyle = xlNone
    end With
    Else
    msgbox "Not found"
    End If

    --
    Regards,
    Tom Ogilvy


    "matpj" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi there,
    > I have the following code that assumes the value it is looking for is
    > always present:
    >
    >
    > Code:
    > --------------------
    >
    > Range(Columns("A:A").Find("Unplanned Prospects").Offset(0, 0), _
    > Columns("A:A").Find("Unplanned Prospects Total").Offset(0, 14)).Select
    > Selection.borders(xlDiagonalDown).LineStyle = xlNone
    > Selection.borders(xlDiagonalUp).LineStyle = xlNone
    > Code:
    > --------------------
    >
    >
    > i've just run this and it couldn't find "Unplanned Prospects" so it

    returned an error.
    > how can I get around this?
    >
    > thanks in advance,
    > Matt
    >
    >
    > --
    > matpj
    > ------------------------------------------------------------------------
    > matpj's Profile:

    http://www.excelforum.com/member.php...o&userid=21076
    > View this thread: http://www.excelforum.com/showthread...hreadid=504857
    >




  4. #4
    Forum Contributor
    Join Date
    03-14-2005
    Posts
    164
    thanks guys, thats great.

    I have it working now!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1