+ Reply to Thread
Results 1 to 3 of 3

Code fails depending on the order in which it is run

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Code fails depending on the order in which it is run

    I would like to attach the full workbook, but there is too much sensitive data that I can’t sanitize it.

    I have two subroutines as indicated below:
    Please Login or Register  to view this content.
    If I run RunPct, first it runs perfectly. Then if I run RunQty, it fails.
    If I run RunQty first, it runs perfectly. Then if I eun RunPct, it fails.

    Both subroutines fail on the same line in CopyMonth:
    Please Login or Register  to view this content.
    I get a runtime error 1004 – Method Range of object worksheet failed.

    shD is defined and LRowD is defined and they point to valid ranges on the spreadsheet.

    Anyone have any idea why the same code run with the same parameters fails if another routine is run first? ShD points to either a percent sheet or a quantity sheet, and yes, the sheets are there. The sheet that gets pointed to is set by the parameter passed.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Code fails depending on the order in which it is run

    This line.
    Please Login or Register  to view this content.
    First Cells object is unqualified. change it to shD.Cells().

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code fails depending on the order in which it is run

    Now you know why I enlisted another set of eyeballs. I had just put this one away to look at later - the problem with both my code and my writing is that it says what I meant to say whether it actually says it or not. I have to let it age to debug it .

    The miracle is that it worked at all.

    Thanks for the catch. That seemed to be the issue.

+ 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. rows in order depending on cell colour
    By kevinless in forum Excel General
    Replies: 1
    Last Post: 06-18-2014, 07:21 PM
  2. VBA code works in one SUB and fails in a different SUB
    By jcaskey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2013, 11:54 AM
  3. If cell is greater then 2 then - code fails!!
    By esbenhaugaard in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-26-2012, 11:52 AM
  4. Code fails with error 1004
    By cdjones in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-22-2010, 06:27 PM
  5. getting duplicated values depending on rank order
    By zbor in forum Excel General
    Replies: 2
    Last Post: 05-28-2009, 03:28 AM
  6. Code fails if ran more than once
    By Christy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-31-2005, 02:05 PM

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