+ Reply to Thread
Results 1 to 11 of 11

for Each worksheet error/bug

  1. #1
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    for Each worksheet error/bug

    i'm creating a file that is supposed to do all the manual work i need.. it has one constant sheet "GMTdata" and other sheets are transient..

    now my problem is this macro:

    Please Login or Register  to view this content.
    that macro above is supposed to redo the same macro for all other sheets except the sheet name "GMTdata". Now to prevent problems with macros doing unwanted stuff on the GMTdata sheet, i added a code that would exit the sub in case the active sheet is the GMTdata sheet along with a mesage box.

    so the macro above will call this other macro:

    Please Login or Register  to view this content.
    now that macro will call all other macros to perform specific tasks on the worksheet... i had to do it this way so its easier to edit it in the future, in case...
    notice the first part of the sub A01_ProcessData has an exit sub statement and a mesage box in case the active sheet is the GMTdata...

    so i tried running the Sub SynthesizeDuplicates_Click but the end result is that, it does nothing, and it just keeps popping the prompt i created, which means either that it has not moved away from the GMTdata sheet, or it has been skipping the if conditions i added...

    any better ideas??
    Last edited by ag273n; 08-09-2013 at 10:32 PM. Reason: removed unnecessary parts of the macro for easy reading
    don't worry, there's a lot of people that are far more confused than you
    but if you liked what i suggested. Click for me the "Add Reputation" - that way, we'd be both happy.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: for Each worksheet error/bug

    Is this line really commented in your code? If yes it is not executed. If your first sheet is "GMT Data", the macro will immediately stop.

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: for Each worksheet error/bug

    In fact, the problem is because you use ActiveSheet

    Please Login or Register  to view this content.
    When you loop through all sheets, the ActiveSheet always remains the first sheet ("GMT Data" in your case)

    You could either activate the sheet before calling A01_ProcessData or pass the sheet as an argument in this function

    Example
    Please Login or Register  to view this content.
    and in your main procedure use :

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: for Each worksheet error/bug

    on your first reply, its not as a comment. i was playing around with it see if there's some way i could make it work.. the message box on that code was a test i tried to see if it can detect all other sheets except the GMTdata sheet.. well, that test worked.. but when i add the actual "call sub" statement... its stops working..

    i cannot activate another sheet given that all other sheets are transient and can be deleted.. unless if there's a way to activate another sheet next to the GMTdata sheet without having to reference the name of the sheet...


    btw, fyi, the first sub "SynthesizeDuplicates_Click" is on the GMTdata module, while the other sub "A01_ProcessData" is on a separate module I inserted.

    the second option that you were saying "or pass the sheet as an argument in this function"
    how do i do that?
    Last edited by ag273n; 08-10-2013 at 12:11 AM. Reason: added extra info/ and format for easy reading

  5. #5
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: for Each worksheet error/bug

    now I tried what you recommended adding

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    and it returned:

    "Compile Error:

    Procedure declaration does not match description of event or procedure having the same name"

    even before I could run the macro...
    maybe because the two subs are located on separate modules.. is that the problem?

  6. #6
    Forum Contributor
    Join Date
    08-11-2012
    Location
    bengalur
    MS-Off Ver
    Excel 2003, 2007
    Posts
    152

    Re: for Each worksheet error/bug

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


    ___________________________________________________________________________________________________________________________________________
    if you feel something has helped, please click * for reputation

    “I have not failed. I've just found 10,000 ways that won't work.”
    ― Thomas A. Edison

  7. #7
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: for Each worksheet error/bug

    I tried that, and sadly, it still didn't work...
    I might as well attach a sample file here for you to try it..

    TEST_TEMPLATE(modified)V6.1 - Copy.xlsm

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: for Each worksheet error/bug

    The code (VBA Project) is password protected... difficult to help.

  9. #9
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: for Each worksheet error/bug

    woops...
    sorry..

    this other file should be easier to access..

    TEST_TEMPLATE(modified)V6.1 - Copy.xlsm

  10. #10
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: for Each worksheet error/bug

    Made 2 smalls changes and it seems to work. Please verify...

    Please Login or Register  to view this content.
    and

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

  11. #11
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: for Each worksheet error/bug

    I am totally amazed... it worked like magic!... thanks a bunch! finally!

+ 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. Replies: 6
    Last Post: 10-17-2013, 02:29 AM
  2. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  3. Copy name of worksheet to an error worksheet
    By mineralfellow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2009, 06:42 PM
  4. Error in userform when error in worksheet
    By sepandb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2008, 10:43 AM
  5. [SOLVED] error with macro to name new worksheet with cell from old worksheet
    By Moon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2005, 02:55 AM

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