+ Reply to Thread
Results 1 to 8 of 8

For Loop Issue

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    For Loop Issue

    I have the following code:

    Please Login or Register  to view this content.
    The WksExists Function:

    Please Login or Register  to view this content.
    The code works fine but it only works for Sheet1 & DataImport2 but not DataImport3.

    Hence why the loop does not copy the relavent data from the DataImport3 page onto a "Sheet3" in SOSCRMTasks.xls

    I am working on an old file at the moment, but in reality the file is more than four pages now . e.g Sheet1, DataImport2, DataImport3, DataImport4 ....

    thank You
    Last edited by pr4t3ek; 11-12-2008 at 10:39 AM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185
    Hi,

    You havent actually asked a question, but I am assuming that you want your code to complete the same loop for each sheet in your workbook, regardless of how many there are?

    If not, could you please give a more detailed explaination of what you want it to do.

    Thanks

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    Sorry,

    What i want to know is why the loop is only doing DataImport2 and not DataImport3.


    And yes i want the code to complete the same loop on all the sheets that start with DataImport and a digit

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985
    Where is the code located - normal module or worksheet module? Also, are you sure that the sheet name matches exactly (no trailing spaces etc)?

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    Hi,
    Yes the sheet name is an exact match except the digit in the end.

    Code is in a normal module i believe.

    The interesting this is that it goes to DataImport2 but not DataImport3 worksheet

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985
    It's probably due to this line:
    Please Login or Register  to view this content.
    You have activated a different workbook and that sheet name probably doesn't exist in that workbook (your wksExists function assumes the activeworkbook). If you must activate it (which is unnecessary and inefficient) then make sure you reactivate the current workbook as soon as you have done what you need to so the loop can continue.
    Last edited by romperstomper; 11-12-2008 at 10:16 AM. Reason: Typo.

  7. #7
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185
    Agreed - you need this line at the end of your loop, above the 'next i'

    Please Login or Register  to view this content.
    That should do the trick, although it's not the best method, it shouldnt hinder you any if you are only looping to 20

  8. #8
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    hmmm that sure is interesting!

    And yes that worked just fine! cheers guys

+ 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