+ Reply to Thread
Results 1 to 17 of 17

Nested For Loop - Correction Needed

  1. #1
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Nested For Loop - Correction Needed

    I am using Nested For Loop in a Macro to split each day in three durations (N.Peak from 00:00 to 11:00 hrs, Peak from 11:00 to 23:00 hrs, and N.Peak from 23:00 to 24:00 hrs), with the exception that Sunday has only one duration ( From Start time to End time if Given, or from 00:00 to 24:00 hrs if it comes in between two dates as full day)


    I have large Number of such days and this macro is generating correct durations for each day other than Sunday.

    For Sunday it is Generating duration from Start time to End time , and also from 00:00 to 24:00 hrs ( As a Full Day , which is not required )

    following is the code. Can anyone correct it for me. I have also attached Excel Sheet with the Sample data and Macro


    Nested For Loop.xlsm


    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    i would appreciate if anybody can help me to correct this code.

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    What about this,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  4. #4
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    No . it is not working properly

    It is generating false output in start time on Sunday.

    I have attached Excel File with your code for your kind refrence

    Nested For Loop R1.xlsm

    Thanks for taking time to help me

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    See if this works then.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    Many thanks for you time and kind reply

    But it is not working properly

    Pl see the attached file

    Nested For Loop R2.xlsm

  7. #7
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    Can anyone help me

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    I honestly do not know what you are trying to do? You are adding data that is not even there? Personally I would rather re-write the entire code if I could understand what it is you are trying to do?

  9. #9
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    Ok

    I have to split approx 100's of entries (From Start Date and Time to End Date and Time) to three duration in each day. (from 00:00 hrs to 11:00 hrs Duration is N.Peak, from 11:00 hrs to 23:00 duration is Peak, and from 23:00 to 24:00 hrs , duration is N.Peak)
    But if day is Sunday, then duration is either "Sunday" from Start Time to End time, or "Sunday" from 00:00 to 24:00 hrs

    Let us Start with examples

    1st Entry

    Sr. No. . . . . . . Start Date & Time. . . . . . . . . End Date&Time. . . . . . Event
    1 . . . . . . . 03-March-13 01:15 . . . . . . . . . 05-March-13 10:55 . . . FO
    2 . . . . . . . 03-March-13 13:00 . . . . . . . . . 11-March-13 23:55 . . . FO


    Spliting Entry 1 . . . . . . . 03-March-13 01:15 . . . . . . . . . 05-March-13 10:55 . . . FO would be as follows

    Sr. No. . . . Start Date . . . . . . Start Time . . . . . . . . End Time . . . . . . Duration . . . . . . Event

    1 . . . . . .03-March-13. . . . . 01:15 . . . . . . . . . . . 02:00 . . . . . . . . Sunday . . . . . . . .FO (First it should complete the running hour, and as Day is Sunday, Duration should also be Sunday)
    03-March-13. . . . . 02:00 . . . . . . . . . . . 24:00 . . . . . . . . Sunday . . . . . . . .FO (As Day is Sunday, so Duration is Sunday till the end of the day)
    04-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    04-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    04-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    05-March-13. . . . . 00:00 . . . . . . . . . . . 10:00 . . . . . . . . Peak . . . . . . . .FO (breaks the time , as minutes are not Zero )
    05-March-13. . . . . 10:00 . . . . . . . . . . . 10:55 . . . . . . . . Peak . . . . . . . .FO (Completes the time to end time)

    In the same way i have to split Entry 2 . . . . . . . 03-March-13 13:00 . . . . . . . . . 11-March-13 22:55 . . . FO as

    Sr. No. . . . Start Date . . . . . . Start Time . . . . . . . . End Time . . . . . . Duration . . . . . . Event

    1 . . . . . .03-March-13. . . . . 13:00 . . . . . . . . . . . 24:00 . . . . . . . . Sunday . . . . . . . .FO (No need to complete the running hour as minutes are Zero, and as Day is Sunday, Duration should also be Sunday till the end of the day)
    04-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    04-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    04-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    05-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    05-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    05-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    06-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    06-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    06-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    07-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    07-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    07-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    08-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    08-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    08-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    09-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    09-March-13. . . . . 11:00 . . . . . . . . . . . 23:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    09-March-13. . . . . 23:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    10-March-13. . . . . 00:00 . . . . . . . . . . . 24:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is sunday, so Duration Criteria does not applies, Duration Criteria is Sunday )
    11-March-13. . . . . 00:00 . . . . . . . . . . . 11:00 . . . . . . . . N.Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies )
    11-March-13. . . . . 11:00 . . . . . . . . . . . 22:00 . . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies , breaks the time to starting hour as minutes are not zero)
    11-March-13. . . . . 22:00 . . . . . . . . . . . 22:55. . . . . . . . Peak . . . . . . . .FO (As Day is not sunday, so Duration Criteria applies , Completes the time )

  10. #10
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    I know you took a long time to post this, but please Post a workbook with sample data.

  11. #11
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    You are realy a kind person
    Following is the sample data
    FO PFO Record.xlsm

  12. #12
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    JapanDave-I hope you must be working on it

  13. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    I thought you got the answer here? http://www.excelforum.com/excel-prog...52#post3212352

    So I did not bother re-doing the code.

  14. #14
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    No answer from there too yet. . . . .

  15. #15
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    Can you please re-do the code for me

  16. #16
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Nested For Loop - Correction Needed

    Not good to start a duplicate thread. I will wait until Watersev has finished, he is a very good coder and should be able to help you out. If you don't get what you want in the end or he does not get back to you (I am sure he will) give me a bell.

  17. #17
    Registered User
    Join Date
    07-29-2010
    Location
    Multan
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Nested For Loop - Correction Needed

    Hi JapanDave

    Many thanks for your patience , although i did wrong by starting another thread for same problem.
    watersev is realy a good coder , and his code is working fine for me.

    I am marking this thread as SOLVED

    http://www.excelforum.com/showthread...t=#post3212924

    You guys are really very kind.

    Kind regards

+ 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