+ Reply to Thread
Results 1 to 5 of 5

VBA Inactive Worksheets

  1. #1
    Registered User
    Join Date
    11-29-2007
    Posts
    15

    VBA Inactive Worksheets

    I am having trouble referencing a range in an inactive worksheet to feed an vba array. this is the following vba code that does not work:

    Please Login or Register  to view this content.
    The error I get is:
    Run-time error '1004'

    Application-defined or object-defined error
    It will work if I activate the sheet but I'm trying to avoid that. The code that will work but trying to avoid is:

    Please Login or Register  to view this content.
    Last edited by tsc35; 12-17-2009 at 11:38 AM.
    Thanks,
    Travis

  2. #2
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: VBA Inactive Worksheets

    Do you now what line the code erorrs on ie 1004 error?

    Also check EVERYTHING is declaired and exists, sheet name, variable etc

    jiuk

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: VBA Inactive Worksheets

    You need to specify the Workbook when the worksheet is not active (From Microsoft):

    Ranges on Inactive Worksheets

    If you want to work efficiently with more than one worksheet at the same time, it is important to be able to refer to ranges on worksheets without having to activate those worksheets. Switching between worksheets is slow, and code that does this is more complex than it need be. This also leads to code that is harder to read and debug.

    All our examples so far apply to the active worksheet, because they have not been qualified by any specific worksheet reference. If you want to refer to a range on a worksheet that is not active, simply use the Range property of the required Worksheet object:

    Please Login or Register  to view this content.
    If the workbook containing the worksheet and range is not active, you need to further qualify the reference to the Range object as follows:

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 12-11-2009 at 04:58 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: VBA Inactive Worksheets

    >>>> Also check EVERYTHING is declaired and exists, sheet name, variable etc

    Yep then you can work with them regardless!!!! Active or not etc

  5. #5
    Registered User
    Join Date
    11-29-2007
    Posts
    15

    Re: VBA Inactive Worksheets

    jrdnoland

    Thanks so much... I knew that but after a long day you start to make mistakes. That's exactly what's going on. I'm declaring the WS but not the WB.

    Many Thanks

+ 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