+ Reply to Thread
Results 1 to 4 of 4

object variable or with block not set

  1. #1
    jhahes
    Guest

    object variable or with block not set

    This is what I currently have, however if my entry is not in the range then it makes me debug saying object variable not set or with block not set. Is there anyway that I can actually have a msgbox "Not found" pop up if the entry entered is not in the list.


    Range("A1:A500").Select
    Dim EmailAddress As String
    EmailAddress = InputBox("enter Email Address", "Email Address")
    Selection.Find(What:=EmailAddress, After:=ActiveCell, LookIn:=xlFormulas, _
    Lookat:=xlPart, Searchorder:=xlByRows, searchdirection:=xlNext, _
    MatchCase:=False, searchformat:=False).Activate


    Thanks for any help

  2. #2
    Ardus Petus
    Guest

    Re: object variable or with block not set

    Dim Found as Range
    .....
    set Found = Selection.Find(...)
    if found is Nothing then msgbox "not found"


    HTH
    --
    AP

    "jhahes" <[email protected]> a écrit dans
    le message de news:[email protected]...
    >
    > This is what I currently have, however if my entry is not in the range
    > then it makes me debug saying object variable not set or with block not
    > set. Is there anyway that I can actually have a msgbox "Not found" pop
    > up if the entry entered is not in the list.
    >
    >
    > Range("A1:A500").Select
    > Dim EmailAddress As String
    > EmailAddress = InputBox("enter Email Address", "Email Address")
    > Selection.Find(What:=EmailAddress, After:=ActiveCell,
    > LookIn:=xlFormulas, _
    > Lookat:=xlPart, Searchorder:=xlByRows, searchdirection:=xlNext,
    > _
    > MatchCase:=False, searchformat:=False).Activate
    >
    >
    > Thanks for any help
    >
    >
    > --
    > jhahes
    > ------------------------------------------------------------------------
    > jhahes's Profile:

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




  3. #3
    jhahes
    Guest

    same error

    I tried the solution and got the same error both times now. When I found the entry and when I didn't find the entry.


    Josh

  4. #4
    Ardus Petus
    Guest

    Re: object variable or with block not set

    This works by me:

    '------------------------------
    Sub test()
    Dim EmailAddress As String
    Dim found As Range
    Range("A1:A500").Select
    EmailAddress = InputBox( _
    "enter Email Address", _
    "Email Address")
    Set found = Selection.Find( _
    What:=EmailAddress, _
    After:=ActiveCell, _
    LookIn:=xlFormulas, _
    Lookat:=xlPart, _
    Searchorder:=xlByRows, _
    searchdirection:=xlNext, _
    MatchCase:=False)
    If found Is Nothing Then
    MsgBox "Not found"
    Else
    found.Activate
    End If
    End Sub
    --

    HTH
    --
    AP

    "jhahes" <[email protected]> a écrit dans
    le message de news:[email protected]...
    >
    > I tried the solution and got the same error both times now. When I
    > found the entry and when I didn't find the entry.
    >
    >
    > Josh
    >
    >
    > --
    > jhahes
    > ------------------------------------------------------------------------
    > jhahes's Profile:

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




+ 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