+ 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
    186

    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
    UK
    MS-Off Ver
    2010 primarily
    Posts
    2,795

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

    You never assigned a range to the Target variable.
    Rory
    There's a row going on down near Slough

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

    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
    18,873

    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
    186

    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
    18,873

    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
    Excel 2007
    Posts
    5,783

    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
    186

    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)

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