+ Reply to Thread
Results 1 to 14 of 14

getting run-time error 91 object variable with block variable not set

  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    getting run-time error 91 object variable with block variable not set

    Hi friends,

    I want to copy-paste the salary of each employee on the ‘Entry’ sheet having a remark ‘ok’ in column ‘Y’ on the ‘Salary’ sheet. If there is no ‘ok’ remark in column ‘Y’ then I want to skip that employee. Now I have no remark ‘ok’ for second employee. So I want to skip him and want to copy-paste only 3 employees’ salary on salary sheet respectively. Here I don’t want to leave the blank rows for second employee.

    I’m getting run-time error 91 object variable with block variable not set.

    Any help will be highly appreciated.

    Thanking you in anticipation.
    Attached Files Attached Files
    Sincerely,

    mso3

  2. #2
    Registered User
    Join Date
    12-20-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    9

    Re: getting run-time error 91 object variable with block variable not set

    hi mso3,

    I have looked into your code,
    You declare "target" variable, but you never use it, or set a value to it.


    Gil

  3. #3
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi Gil,
    Thank you for your response.

    The number of employees may vary time to time.
    I want to shorten the code to achieve the target.

    Please suggest me a code to achieve the target. What change should I do in the code for require output.

    Thanking you,

  4. #4
    Registered User
    Join Date
    12-20-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    9

    Re: getting run-time error 91 object variable with block variable not set

    it should be something like this:

    Sub copySalary()
    Dim src As Range
    Dim dst As Range

    Set src = ThisWorkbook.Worksheets("entry").Range("a4:a100")

    Set dst = ThisWorkbook.Worksheets("salary").Range("a6")

    For i = 1 To src.Rows.Count
    If IsNumeric(src.Rows(i, 1)) And src.Rows(i, 25) = "ok" Then
    dst(i, 1) = src(i, 1)
    dst(i, 2) = src(i, 2)
    dst(i, 3) = src(i, 24)
    End If
    Next

    End Sub

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi Gil,

    Thank you.

    I’m getting ‘run-time error 1004 application-defined or object-defined error’ on the following line:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanking you,

  6. #6
    Registered User
    Join Date
    12-20-2015
    Location
    Israel
    MS-Off Ver
    2013
    Posts
    9

    Re: getting run-time error 91 object variable with block variable not set

    sorry

    here is the fix:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,722

    Re: getting run-time error 91 object variable with block variable not set

    See attached

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi jolivanes,
    Greetings from me!

    Thank you. The code is working fine but I need the following amendments in it.

    1. Each entry contains 3 rows which should be copied on salary sheet. Now only first row of each entry is being copied on the salary sheet.

    2. There is a blank row in between each entry which should be there on the salary sheet.

    Everything else is fine.

    After these 2 amendments the code will be perfect as per my requirement.

    Thank you and have a nice time.

  9. #9
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi Gil,

    Sorry! The code is not working as per requirement. It copies only first 3 cells of each entry and leaving blank rows for skipped entry here entry 2.

    Thank you.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,722

    Re: getting run-time error 91 object variable with block variable not set

    Try this.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi jolivanes,
    Thank you. Sorry, still it's not working. Now it's not copying any entry. The 'ok' remark is in column 'Y' 25. I changed it but no output.

    Please see the attached workbook and suggest me a solution.

    Thanking you.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi Gil,

    I have amended the code as follows and got the entire first row on salary sheet. Now I want the second and third row of each entry on salary sheet and a blank row in between each entry.

    Please Login or Register  to view this content.
    Thanking you.

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,722

    Re: getting run-time error 91 object variable with block variable not set

    Works for me.
    The only thing I changed is that I assigned the new code to the button
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: getting run-time error 91 object variable with block variable not set

    Hi jolivanes,

    Excellent! I pasted the code in new workbook and now it's working fine.

    I appreciate you for the same.

    Thank you and have a nice time.

+ 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. [SOLVED] Run-time error 91: Object variable or With block variable not set
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2015, 09:29 AM
  2. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  3. Run Time Error 91 - Object Variable or With block variable not set
    By tony707 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-18-2013, 04:09 PM
  4. Run-time error 91 - Object variable or with block variable not set
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-31-2012, 06:08 PM
  5. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  6. Replies: 1
    Last Post: 09-25-2012, 08:03 PM
  7. [SOLVED] Intermittent Run-time Error 91: Object Variable or With Block variable not set
    By fraanchtoast in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-29-2012, 10:11 AM

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