+ Reply to Thread
Results 1 to 8 of 8

object variable or with block variable not set, Problem

  1. #1
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    object variable or with block variable not set, Problem

    Hi

    This is a problem that I can't seem to solve.
    I have Uploaded a sample sheet with just enough code for it to run.
    I have all so uploaded a picture tha shows the code and the error message.

    On Sheet "BEREGNING" there is a Button "NEW ROW" that gives me the error "object variable or with block variable not set"

    Can some one please help me with this.

    Udklip.JPG
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: object variable or with block variable not set, Problem

    You never assigned a range to the Target variable.
    Rory

  3. #3
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: object variable or with block variable not set, Problem

    Thanks Roya

    I don't know how I missed that, stupid mistake, But being still new in learning VBA, they do happen :-)

    So I sorted that out :
    Please Login or Register  to view this content.
    And it now works but needs some ajustments to the copy row part.
    I need this part to Exit sub witout doing anything if cancel is selected
    Please Login or Register  to view this content.
    New Sample uploaded Translated to English

    New Picture
    Attachment 624738
    Attached Files Attached Files

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

    Re: object variable or with block variable not set, Problem

    If cancel is selected where/when?
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: object variable or with block variable not set, Problem

    Hi Norie

    Here:
    Please Login or Register  to view this content.
    Attachment 624740

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

    Re: object variable or with block variable not set, Problem

    I can't find any code that uses vbCancel in the workbook you attached.

    The closest thing I can find is this,
    Please Login or Register  to view this content.
    which is in the sub InsertNewRow in the module NEWROW.

    When I click Cancel on the message box generated by that code the code terminates.

    Mind you the code before this code appears to be inserting rows, so perhaps the above code isn't located in the correct place?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: object variable or with block variable not set, Problem

    I think you are confusing yourself by using designated terms like Target, Cancel and Application.EnableEvents which have a fixed meaning in Event-codes.

    Using Cancel in Event-codes is handled in source code of XL. When you use Cancel like you do it's just another variable to which you assign a certain value.

    You will have to write/check a certain condition and based on that outcome you can use Exit Sub or go on.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: object variable or with block variable not set, Problem

    Thanks bakerman2

    Yes, it just needed some tidying up and some re-thinking.
    It was actualy a mess :-)

    Nice breakfast and coffe, a good nights sleep, then it just was so simple.

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

+ 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. Object variable or with block variable not set problem
    By Wilftiger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2019, 06:56 AM
  2. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  3. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  4. Macro issue: Object variable or with block variable not set error
    By utgjmb1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-29-2013, 06:07 AM
  5. Replies: 1
    Last Post: 07-24-2013, 02:45 PM
  6. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  7. Replies: 6
    Last Post: 12-21-2012, 08:03 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