+ Reply to Thread
Results 1 to 8 of 8

Need help writing Loop syntax

  1. #1
    Registered User
    Join Date
    10-29-2008
    Location
    michigan
    Posts
    15

    Need help writing Loop syntax

    Hi Everyone,

    I am limited in coding using macros/vba for excel, so would greatly appreciate if someone could help me with the syntax. Here is what I need, and sample data attached:

    Loop
    Length - run until the end of data in column A

    Test#1
    Starting with "MAY 04", I want to run a loop that checks "MAY 04" against every month in the same row to see if there is data present in both months on the same date. If YES, then return the two header rows in the format "MAY 04^JUN 04".

    Then repeat this loop for each of the months in the header row from left to right...i.e, "JUN 04" against "JUL 04", "AUG 04", "SEP 04", etc. "JUL 04" against "AUG 04", "SEP 04", "OCT 04", etc.

    Continue this loop until all the months in the header row have been checked.

    Output
    The final output would be a list of all the months with data present on the same date (duplicates removed)

    Have a look at the attached spreadsheet, I think I have the test criteria for the loop that will work.

    SampleData1.xlsx
    Last edited by sslack88; 06-24-2012 at 07:18 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Need help writing Loop syntax

    Hi

    Not sure I really follow your output structure. In row 3 you have data in May, Jun, Aug and Nov. The output is in May (for May and Jun), Jul (for May and Aug) and Oct (for May and Nov). Why are they out a month. Also, where would you want to put the results for Jun and Aug, Jun and Nov and Aug / Nov?

    rylo

  3. #3
    Registered User
    Join Date
    10-29-2008
    Location
    michigan
    Posts
    15

    Re: Need help writing Loop syntax

    Sorry, that was confusing and incorrect.....the header row in the test criteria now represents the month we are testing MAY 04 against. Also, I show what I want the final output to be.

    Let me know if anything else isn't clear

    See attached:
    SampleData1.xlsx

    One last thing....I don't need to see the test criteria columns on the spreadsheet, I just need the final output. I was only showing that as an example. So the output would just be a list of all the months that have data on the same date. For example:

    MAY 04^JUN 04
    MAY 04^AUG 04
    MAY 04^NOV 04
    JUN 04^JUL 04
    JUN 04^AUG 04
    JUN 04^NOV 04

    etc.
    Last edited by sslack88; 06-24-2012 at 07:24 PM.

  4. #4
    Registered User
    Join Date
    10-29-2008
    Location
    michigan
    Posts
    15

    Re: Need help writing Loop syntax

    ..............................
    Last edited by sslack88; 06-24-2012 at 07:26 PM.

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Need help writing Loop syntax

    Hi

    See how this goes
    Please Login or Register  to view this content.
    rylo

  6. #6
    Registered User
    Join Date
    10-29-2008
    Location
    michigan
    Posts
    15

    Re: Need help writing Loop syntax

    Thanks Rylo for giving this a shot....seems there is a small error in the output, but the concept is what I was looking for. Here is the output I am getting, could you help try to see where the errors might be creeping in.

    MAY 04^JUN 04
    MAY 04^JUL 04 .........'shouldn't exist on list
    MAY 04^AUG 04
    MAY 04^SEP 04 ........'shouldn't exist on list
    MAY 04^OCT 04 ........'shouldn't exist on list
    MAY 04^NOV 04
    JUN 04^ ..................'picking up 3rd row blank cell for second month (JUL 04)
    JUN 04^20.11 ...........'picking up 3rd row for second month (AUG 04)
    JUN 04^20.94 ...........'picking up 3rd row for second month (NOV 04)
    JUL 04^ ..................'should have two sets listed for july.....Jul 04^Aug 04 and Jul 04^Nov 04
    AUG 04^ .................'should have two sets listed for august...Aug 04^Sep 04 and Aug 04^Nov 04
    SEP 04^ .................'picking up blank cell for second month, should be SEP 04^OCT 04
    SEP 04^20.98 ..........'picking up 6th row for second month (Nov 04)
    OCT 04^21.02 ..........'picking up 7th row for second month (Nov 04).
    Last edited by sslack88; 06-24-2012 at 09:25 PM.

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Need help writing Loop syntax

    Hi

    Sorry about that. Only forgot the critical part of the test and got the wrong row... Not my day sofar.

    Please Login or Register  to view this content.
    rylo

  8. #8
    Registered User
    Join Date
    10-29-2008
    Location
    michigan
    Posts
    15

    Re: Need help writing Loop syntax

    Thanks Rylo, that did the trick!

+ 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