+ Reply to Thread
Results 1 to 7 of 7

looping issues

  1. #1
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    looping issues

    Greetings:

    I知 working on a macro to generate work schedules for a boat yard, and I could sure use some expert opinions. I知 taking an exported customer file from QB, running multiple, conditional delete subs, and now I need to have it calculate the next scheduled service date based on schedule type (col. G), last service date (col. M), and next scheduled service date (col. N), and enter the calculated service date to column T.

    Note - The next scheduled service date (column N) is an entry that clerks make when a customer requests service outside of the normal cycle. If found and the date in col. N is >= to Today, it should override the calculated value.

    Logically, the DateCalc sub should:
    (1) Establish the range of the loop (G2 to last non-blank row)
    (2) for each cell in the selected range, and based on the value in col. G (CType = Schedule Type (SchedType)), the value in col. M (CUSTFLD6 = Last Service Date (LastSvcDate)), calculate the next scheduled service date (NextSchedSvc);
    (3) compare the value in Calculated Service Date (NextSchedSvc) to the value in col. N (CUSTFLD7 = Next Scheduled Service (NextSvcDate));
    (4) if col. N is not blank and the value >= to today, then the Calculated Scheduled Service Date (NextSchedSvc) = Column N value, else the Calculated Next Scheduled Service Date (NextSchedSvc) should remain as calculated, and
    (5) enter the calculated value to column T of that row

    Believe it or not this is my introduction to VBA Programming. Nothing like jumping into the deep end of the pool!

    I have included the entire macro code base to keep the overall structure in context. I realize that the DateCalc sub needs a boatload of work yet, but it痴 prettier than it was yesterday at this time. I have also attached the customer file it痴 running against. So, with all that said, what I知 struggling with at this point is (1) whether I need to define the range for other columns in addition to column G, or is it sufficient to establish a range for column G, and (2) am I on the right track in terms of my approach. For example, would I be better off doing this with a Select Case or ElseIf structure, or is the way I知 working through it equally as efficient?

    Thanks in advance - Marcus

    HTML Code: 

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I haven't read through your code, but I can answer your first question.

    if myColG is a range variable of cells in Column G,

    Please Login or Register  to view this content.
    is the same cells 2 columns to the right.
    While,
    Please Login or Register  to view this content.
    includes the intermediate cells.

  3. #3
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    Use of Do Until IsEmpty rather than Range

    Thanks Mikerikson - I recall reading in one of the moderator's postings that setting ranges in general is a bad idea. Given that, and taking your reply into account, I'm beginning to think a better approach would be to use a Do Until IsEmpty routine together with the offset you mentioned to specify which cells to use in calculating the next service date.

    Is that a better approach? Any advice you can offer is appreciated. Thanks again - Marcus
    Last edited by Marcus Gee; 10-09-2007 at 05:03 PM. Reason: wrong title

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I'm not sure what you mean by "setting ranges in general is a bad idea".

    Using range variables is a common way to avoid Selecting ranges. It is faster and all around better than Selecting.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Marcus, try this.

    BTW, I've seen lots of mikerickson's posts, and commend his advice.

    Please Login or Register  to view this content.
    Last edited by shg; 10-09-2007 at 08:16 PM.

  6. #6
    Registered User
    Join Date
    08-27-2007
    Location
    San Antonio Texas
    Posts
    41

    Thank you, Thank you, Thank you!

    Mikerickson and SHG - Thanks a million - I took your code and plugged it in, then went through it to add some comments (to ensure I knew what it was doing). I made one change that worked (moving the statement that posts the datNextSvc to the active row, column T to just above the End If Statement).

    I made one other change that didn't work, that being date calc for "OnCall" services. For some reason the code I entered returns a value of 12:00:00 PM.

    In the process of running the code I also discovered that one of the admin people had entered a Schedule Type of Contract for some reason, which crashes the sub. I'll need to add some code at some point to identify entries other than the designated schedule types and put it on an error report, but other than that, it works. I've included the (slightly) modified code below.

    Again, thank you. Y'all made my week!

    Marcus

    HTML Code: 

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Glad to see you're on your way Marcus. As you're new to VBA, please ponder the code and internalize the logic and structure.

    Post back if you have problems.

    I would also recommend that you update and extend the comments. You will revisit this code someday.
    Last edited by shg; 10-10-2007 at 12:13 AM.

+ 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