+ Reply to Thread
Results 1 to 7 of 7

Macro stops working when I go to a different worksheet

  1. #1
    Registered User
    Join Date
    07-31-2012
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Macro stops working when I go to a different worksheet

    Hello,
    The below code works as long as I am in "Peak WL 7914" worksheet. If I go to another worksheet I get the runtime error: "application defined or object defined error".
    Please help, thanks in advance


    Please Login or Register  to view this content.
    Last edited by gandrea; 08-31-2012 at 01:43 PM. Reason: solved

  2. #2
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: Macro stops working when I go to a different worksheet

    do you need to run the code for each sheet or does it only need to run on "Peak WL 7914"?

    if only that sheet, just put:
    Please Login or Register  to view this content.
    at the start of your code

    if you want it to run on each sheet then youll need to add something like

    Please Login or Register  to view this content.
    Last edited by tbar05; 08-30-2012 at 07:30 PM. Reason: tags

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro stops working when I go to a different worksheet

    @gandrea
    @tbar05

    Please add code tags around your code.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    07-31-2012
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro stops working when I go to a different worksheet

    tbar05,

    Answering your question: I only need to run the code on the "Peak WL 7914" sheet.

    I added .Select (see code below) as you suggested and the macro continues to run if i go to a different worksheet. However, when I am on a different sheet and the macro runs, I am taken back to the "Peak WL 7914" sheet. Is there a way to have the macro run and stay on the sheet that I am looking at?

    Please Login or Register  to view this content.
    Thanks

  5. #5
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro stops working when I go to a different worksheet

    Try changing this line:

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Does that work? Please report back

  6. #6
    Registered User
    Join Date
    07-31-2012
    Location
    Palo Alto, CA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro stops working when I go to a different worksheet

    BigBas!! yes it works.

    Please Login or Register  to view this content.
    Thanks a million

  7. #7
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro stops working when I go to a different worksheet

    No problem.

    It doesn't seem logical, but when you are referencing the Cells formula, it refers to the ActiveSheet if not qualified. Of course, this will throw an error in many cases. By adding the ".", it then references the "Peak WL 7914" sheet per the With statement.

+ 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