+ Reply to Thread
Results 1 to 5 of 5

Run Time Error '91' Object Variable or block variable not set

Hybrid View

leao67 Run Time Error '91' Object... 07-18-2013, 11:05 PM
Solus Rankin Re: Need help coding 07-19-2013, 12:28 AM
arlu1201 Re: Need help coding 07-19-2013, 01:26 AM
JosephP Re: Run Time Error '91'... 07-19-2013, 10:47 AM
Solus Rankin Re: Run Time Error '91'... 07-19-2013, 10:49 AM
  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    2

    Run Time Error '91' Object Variable or block variable not set

    I am writing a code for my job but I have hit a road block. I need to write a macro that checks sheet 1 for a specific number then if that number is not found then it searches three other sheets and if the number is found it deletes it. My problem is that I get an error (Run Time Error '91' Object Variable or block variable not set) when i run the program for a number that is not found on one of the subsequent sheets. Ive been working on this for days and I cant figure it out. Heres the code with the number replaced with stars

    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Sheets("Master").Select
        If Range("C1").Value = "*********" Then
        
        Else
        Sheets("ERT").Select
        If Cells.Find(What:="***********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate = True Then
        ActiveCell.ClearContents
        End If
        Sheets("FT Phone").Select
        If Cells.Find(What:="**********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate = True Then
        ActiveCell.ClearContents
        End If
        Sheets("Staff Does Not Report").Select
        If Cells.Find(What:="**********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate = True Then
        ActiveCell.ClearContents
        End If
    End If
    
    End Sub
    Last edited by leao67; 07-19-2013 at 10:38 AM.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Need help coding

    When posting code please use code brackets. To do this, highlight your code and press the # button in the toolbar.

    What error are you getting?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need help coding

    Thanks Solus.

    leao67,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE] before your code and [/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run Time Error '91' Object Variable or block variable not set

    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
       Dim rFound as Excel.Range
        Sheets("Master").Select
        If Range("C1").Value = "*********" Then
        
        Else
        Sheets("ERT").Select
        Set rFound = Cells.Find(What:="***********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
       if not rfound is nothing then rFound.ClearContents
        Sheets("FT Phone").Select
        Set rFound = Cells.Find(What:="**********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
       if not rfound is nothing then rFound.ClearContents
        Sheets("Staff Does Not Report").Select
        Set rFound =  Cells.Find(What:="**********", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
       if not rfound is nothing then rFound.ClearContents
    End If
    
    End Sub
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Run Time Error '91' Object Variable or block variable not set

    You don't have a statement for then

        Sheets("Master").Select
        If Range("C1").Value = "*********" Then
        
        Else
        Sheets("ERT").Select

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Coding Style - Exit Points - What are good methods for coding Exit Points?
    By CHatmaker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2013, 05:30 PM
  2. [SOLVED] CheckBox coding to work with ComboBox coding
    By JimExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2013, 12:23 PM
  3. Coding and Reverse Coding a Questionnaire
    By lorr3 in forum Excel General
    Replies: 2
    Last Post: 11-18-2012, 06:43 PM
  4. [SOLVED] Implant macro coding into ASP coding
    By Sam yong in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2005, 06:05 AM
  5. Need coding help.
    By Neddy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-17-2005, 08:05 AM

Tags for this Thread

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