+ Reply to Thread
Results 1 to 4 of 4

Run-time error '91': - Object variable or With block variable not set (HELP!)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Heckmondwike, England
    MS-Off Ver
    Excel 2007, 2010, 2013
    Posts
    54

    Run-time error '91': - Object variable or With block variable not set (HELP!)

    Hi All,

    I thought I had completed a spreadsheet I've spent months working on when I have started seeing an error when I run a macro

    Run-time error '91':

    Object variable or With block variable not set
    ===========

    It seems to work correctly when i run it at work, but I dont believe anything has changed.

    This is one of the macro codes where I see the error

    Sub homethreedart():
    
    ActiveSheet.Unprotect
    Dim r As Range, S As String, c As Long
    Set r = Range("B34:H34")
    S = Range("B1"): c = r.Find(S).Column
    Cells(35, c) = 3
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    The : c = r.Find(S).Column being highlighted yellow

    Anyone able to shed some light on this please?

    Darren

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,663

    Re: Run-time error '91': - Object variable or With block variable not set (HELP!)

    Dim C as Variant
    Dim Col as Long
    set c = r.Find(S)
    Col = c.column
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Heckmondwike, England
    MS-Off Ver
    Excel 2007, 2010, 2013
    Posts
    54

    Re: Run-time error '91': - Object variable or With block variable not set (HELP!)

    A bit of a beginner, so took a guess at amending to the following code

    ActiveSheet.Unprotect
    Dim C As Variant
    Dim Col As Long
    Set C = r.Find(S)
    Col = C.Column
    Set r = Range("B34:H34")
    S = Range("B1"): C = r.Find(S).Column
    Cells(35, C) = 3
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub
    Now got a 424 object required error

    with the Set C = r.Find(S) highlighted,

    Sorry to be a pain.

    Darren

  4. #4
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Run-time error '91': - Object variable or With block variable not set (HELP!)

    You messed up your code a bit
    This should work:
    Sub homethreedart():
    
    ActiveSheet.Unprotect
    Dim r As Range, S As String, col As Long, c As Range
    Set r = Range("B34:H34")
    S = Range("B1")
    Set c = r.Find(S)
    col = c.Column
    Cells(35, col) = 3
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub

+ 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