+ Reply to Thread
Results 1 to 5 of 5

Run-time error '91': Object variable or With block variable not set

Hybrid View

  1. #1
    Registered User
    Join Date
    01-25-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    7

    Run-time error '91': Object variable or With block variable not set

    Hi,

    Would anyone know how to resolve this error?

    It's this part of the code that's causing it.
    Selection.Find(What:="********REPORT********", After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
        Range("A72:I72").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Delete Shift:=xlToLeft
    I essentially want to delete all rows including this one (based on the find search) to the end of the sheet,row1048576. It seems the way I have done this has restrictions on the row # (A72:I72) - This would change each day depending on the size of the report. I want to be able to just delete all information based on what row the find criteria is.

    I may have 2 issues, 1 being the error 91, and the other for selecting which rows to delete based on what row the find criteria is in.

    This is a work around to clean up a report that is in xml format. some companies just aren't up to speed in reporting (no csv, xsl, or text).

    Thanks for the help.
    Last edited by Leith Ross; 01-26-2009 at 12:07 AM.

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    You could do with attaching a workbook, however your error 91 is because the find hasn't found anything so you need to handle that, here's a way:
    On Error Resume Next
            Selection.Find(What:="********REPORT********", After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
        Range("A72:I72").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Delete Shift:=xlToLeft
    On Error GoTo 0
    Not all forums are the same - seek and you shall find

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Run-time error '91': Object variable or With block variable not set

    Hi

    Try:

    Dim rFound As Range
    
    With ActiveSheet
      Set rFound = .Cells.Find(What:="********REPORT********", After:=ActiveCell, _
            LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
    'check if anything found:
        If Not rFound Is Nothing Then  'if it isn't nothing then it's something ie it was found!
            Application.Intersect(.Range(rFound, .Cells(.Rows.Count, .Columns.Count)), .UsedRange).Delete Shift:=xlToLeft
        End If
    End With
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  4. #4
    Registered User
    Join Date
    01-25-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Run-time error '91': Object variable or With block variable not set

    Thanks for the help everyone. Richard, it worked perfectly.

  5. #5
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: Run-time error '91': Object variable or With block variable not set

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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