+ Reply to Thread
Results 1 to 5 of 5

Code will only execute from one sheet

  1. #1
    Registered User
    Join Date
    10-18-2010
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    47

    Question Code will only execute from one sheet

    Hello, I have read this user form code eight thousand times and cannot find what I am missing but this code currently will only run if the active sheet is "DATABASE". If I attempt to run it with another sheet active I get Run Time Error 1004: Application-defined or object-defined error.

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

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Code will only execute from one sheet

    Hi Kirsty,

    The only thing that comes to mind right away is the line
    Please Login or Register  to view this content.
    If the DATABASE sheet is not active, it will throw an error as you cannot select a range on an inactive worksheet/book.

  3. #3
    Forum Contributor
    Join Date
    05-09-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    315

    Re: Code will only execute from one sheet

    It's because you're referencing Worksheets("DATABASE"). Try using ActiveSheet, although this could produce errors if you try and run the code on a sheet which isn't set out exactly the same as "DATABASE".

    Dion


    Please Login or Register  to view this content.

    ps. You'll need to change the reference in Userform_Activate also.

  4. #4
    Registered User
    Join Date
    10-18-2010
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Code will only execute from one sheet

    Paul, thank you so much. I understand now and will try to fix it and may be back if I cannot. :P

    mojo249, the end code must be able to run from any activesheet so unfortunately that solution will not work for me. Thank you!

  5. #5
    Registered User
    Join Date
    10-18-2010
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Code will only execute from one sheet

    I am going to ask for advice before I start this actually. Currently I have one module that creates reports based on a selection from the database sheet. I am working on a userform that allows other users to select from a listbox which reports they would like to generate. My plan was to have the userform select the desired cells in the database and then run the report creation macro. I do not want the users to have direct access to the database worksheet though so I wanted it to remain hidden throughout. If I cannot select the cells on an inactive worksheet (and I don't believe it is possible to activate a hidden worksheet) what is the best way to accomplish this?

    Is this description clear enough?

+ 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