+ Reply to Thread
Results 1 to 8 of 8

I m getting the error: Runtime error 91: “ Object variable or With block variable not set”

  1. #1
    Registered User
    Join Date
    05-17-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    5

    I m getting the error: Runtime error 91: “ Object variable or With block variable not set”

    I was asked to design the work allotment process for the company. Work is allotted in the given manner: If suppose a task T1 is allotted to a person for 5 days, it should be displayed against his name for 5 consecutive days in the work allotment file. I have written a Visual basic code in MS Excel using macros in the third sheet - MAY of workallotment.xlsm and the tasks are in file tasks.xlsx . I m getting the error: Runtime error 91: “ Object variable or With block variable not set” while searching for the members name in workallotment.xlsm

    I have also tried setting the findrow variable like "set FindRowNumber = rngFindValue.Row" But I get a compiler error saying object required .I attach both the files workallotmetn.xlsm and tasks.xlsx
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    If rngFindValue is Nothing you should exit the sub after displaying the message box.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-17-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    5

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    Even if I end the loop and end sub after the statement "If rngFindValue is Nothing " it still is showing the same runtime error.Please refer to the code below:


    Sub Exercise()

    Dim Arr As Variant, Arr1 As Variant
    Dim iCol As Integer
    Dim FindRowNumber As Integer
    Dim i As Integer, x As Integer
    Dim name As String
    Dim rngFindValue As Range




    'name = Cells(1, 1).Value
    Arr = Workbooks.Open("E:tasks.xlsx").Sheets("Sheet1").Range("B1:E1").Value
    Arr1 = Workbooks.Open("E:tasks.xlsx").Sheets("Sheet1").Range("B2:E2").Value
    Sheets(1).Cells(1, 1).Select

    For i = 1 To Arr1(1, 1)
    Cells(6, 4 + i).Value = Arr(1, 1)
    a = i + 4
    Next i


    For i = 1 To Arr1(1, 2)
    Cells(6, a + i).Value = Arr(1, 2)
    b = a + i
    Next i

    For i = 1 To Arr1(1, 3)
    Cells(6, b + i).Value = Arr(1, 3)
    C = b + i
    Next i

    For i = 1 To Arr1(1, 4)
    Cells(6, C + i).Value = Arr(1, 4)
    d = a + i
    Next i



    Do While ActiveCell.Row <> Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
    ActiveCell.Offset(2, 0).Select
    name = ActiveCell.Value
    Arr = Sheets(1).Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 5)).Value
    Arr1 = Sheets(1).Range(ActiveCell.Offset(1, 1), ActiveCell.Offset(1, 5)).Value



    Set rngFindValue = Sheets(3).Range("A1:A100").find(What:=name, After:=Sheets(3).Range("A1"), LookIn:=xlFormulas)




    FindRowNumber = rngFindValue.Row


    For i = 1 To Arr1(1, 1)
    Cells(FindRowNumber, 4 + i).Value = Arr(1, 1)
    a = i + 4

    Next i


    For i = 1 To Arr1(1, 2)
    Cells(FindRowNumber, a + i).Value = Arr(1, 2)
    b = a + i
    Next i

    For i = 1 To Arr1(1, 3)
    Cells(FindRowNumber, b + i).Value = Arr(1, 3)
    C = b + i
    Next i

    For i = 1 To Arr1(1, 4)
    Cells(FindRowNumber, C + i).Value = Arr(1, 4)
    d = a + i
    Next i


    If Not rngFindValue Is Nothing Then
    MsgBox ("not found")
    End If

    Loop

    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    This is in the wrong place
    Please Login or Register  to view this content.
    The If should be directly after the line of code that does the find and the End If should be just before Loop.

    Also, the message box is wrong - if rngFindValue isn't Nothing it means something has been found.

    I would suggest dropping the message box anyway unless you want to have to click a whole load if them as you loop.

    PS Can you add code tags when posting code?

  5. #5
    Registered User
    Join Date
    05-17-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    5

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    Is this how you want me to change the code ?
    Please Login or Register  to view this content.
    But I want to assign the values I read from tasks.xls to 2 arrays and then to store in the file workallotment.xlsm in the correct row where the name is found .If I end sub after "If rngFindValue is Nothing " how will I be able to do it?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    No, like this.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-17-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    5

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    Thanks a lot !!!! If I insert the above code , the errors are rectified..but the output is not displayed correctly.I am not able to display the tasks by searching the name of the person and displaying the tasks against his name.Can you help me with that .Sorry if I m disturbing you...

    **Workallotment.xlsm** - **Output**
    1 2 3 4 5 6 7 8 9 10 11 12
    Praveen T1 T1 T1 T1 T2 T2 T2 T3 T4 T4
    Bharath Vijay
    Kailash
    Sriram
    Walter c1 c2 c2 c3 c3 c3 c4 c4 c4 c4
    Harshith
    Karthik P1 P1 P1 P1 P1 P1 P2 P2 P2 P3 P3 P4
    Arvind
    Anirudh-Mob apps
    Sharath

    **Tasks.xls** (input)

    Praveen T1 T2 T3 T4
    4 3 1 2
    Karthik P1 P2 P3 P4
    6 3 2 2
    Walter c1 c2 c3 c4
    1 2 3 4


    But I get only (Actual output) after pasting above code

    Praveen T1 T1 T1 T1 T2 T2 T2 T3 T4 T4
    Bharath Vijay
    Kailash
    Sriram
    Walter
    Harshith
    Karthik
    Arvind

    Anirudh-Mob apps
    Last edited by krishnang; 05-18-2016 at 04:42 AM.

  8. #8
    Registered User
    Join Date
    05-17-2016
    Location
    Chennai
    MS-Off Ver
    2010
    Posts
    5

    Re: I m getting the error: Runtime error 91: “ Object variable or With block variable not

    Are there any updates on this one ?

+ 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. Runtime Error 91 Object Variable or With Block not Set
    By wkddj51 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2015, 06:05 AM
  2. [SOLVED] Runtime Error "91" - Object Variable or With Block Variable not set
    By damidre in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-05-2013, 04:45 AM
  3. Runtime Error 91 - object variable or with block variable not set
    By 0celj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2013, 09:40 PM
  4. runtime error 91 object variable or With block variable not set
    By tullemann in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2011, 01:27 PM
  5. Replies: 8
    Last Post: 02-17-2009, 02:24 PM
  6. Runtime error 91 - Object variable or with block variable not set
    By Christian411 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-04-2008, 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