+ Reply to Thread
Results 1 to 17 of 17

VBA: Auto update a weekly schedule

  1. #1
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    VBA: Auto update a weekly schedule

    I have a sheet I use to schedule service for clients on a weekly basis. Once the schedule date is passed, I'm having to re-enter the new scheduled date for service. I'm looking to auto update the next service date, 7 days from the previous scheduled date. Any idea on a formula to use to auto update the next scheduled service date?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,004

    Re: Auto update a weekly schedule

    Maybe use another column to calculate.

    C4
    =IF(A4>$A$2,A4,A4+7*ROUNDUP(($A$2-A4)/7,0))

    copied down.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: Auto update a weekly schedule

    Thank you for the reply. I see how that formula will work for finding the next scheduled service date. I see that it uses the original date in A4. I don't see that the date in C4 will auto update once the current date passes 7/17, or the date in C7 will update once the current date passes 7/21. Any ideas?? Thanks.

  4. #4
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,004

    Re: Auto update a weekly schedule

    I set the A2 to 2023/7/17 18:41,C4 becomes to 2023/7/24 14:00. It's right?

    Could you upload a sample file to describe these problem?

  5. #5
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: Auto update a weekly schedule

    Quote Originally Posted by windknife View Post
    I set the A2 to 2023/7/17 18:41,C4 becomes to 2023/7/24 14:00. It's right?

    Could you upload a sample file to describe these problem?
    No, A2 needs to stay the same. See the new attached workbook.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,004

    Re: Auto update a weekly schedule

    My solution freezes A4:A7 as starting date.

    C4:C7 is various date according to A2.

    You can see attachment as detail.

    If you want to let A4:A7 auto cacluate, I think you need VBA.
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,911

    Re: Auto update a weekly schedule

    Another way:

    =IF(A4>$A$2,A4,A4+CEILING($A$2-A4,7))

  8. #8
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: Auto update a weekly schedule

    Quote Originally Posted by windknife View Post
    If you want to let A4:A7 auto cacluate, I think you need VBA.
    I think you are right. I have no idea how to do that. Much appreciated for your help.

  9. #9
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: Auto update a weekly schedule

    Quote Originally Posted by Phuocam View Post
    Another way:

    =IF(A4>$A$2,A4,A4+CEILING($A$2-A4,7))
    Thank you for the reply. This seems to work as well, but I was looking for something that will update the date & time every 7 days. Like windknife said, VBA is probably the way to go.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,852

    Re: Auto update a weekly schedule

    Shall I move this to the VBA section for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: Auto update a weekly schedule

    Quote Originally Posted by AliGW View Post
    Shall I move this to the VBA section for you?
    Yes please. Thank you.

  12. #12
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: VBA: Auto update a weekly schedule

    This code will automatically run every time the sheet is activated. It will compare column A to cell A2 and update column A accordingly.
    Please note that in order to update column A, sheet 1 needs to be activated.
    Right click on sheet 1 tab, View Code, then paste the code into:
    Save fie as .xlsm
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Activate()
    Dim lr&, cell As Range
    lr 
    Range("A4").End(xlDown).Row
    For Each cell In Range("A4:A" lr)
        If 
    Range("A2") > cell Then
            cell 
    cell 7
        End 
    If
    Next
    End Sub 
    Attached Files Attached Files
    Quang PT

  13. #13
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: VBA: Auto update a weekly schedule

    Thank you for the reply. I tried using that code and saving as an xlsm, the dates are not updating 7 days ahead. See the attached. Any ideas?? Thanks.
    Attached Files Attached Files

  14. #14
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: VBA: Auto update a weekly schedule

    Quote Originally Posted by Ltat42a View Post
    Thank you for the reply. I tried using that code and saving as an xlsm, the dates are not updating 7 days ahead. See the attached. Any ideas?? Thanks.
    Works fine for me with your uploaded file.

    Remember this code is triggered by the worksheet activate event.
    If you are already on this worksheet just click on another tab and then click back and it should run.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  15. #15
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: VBA: Auto update a weekly schedule

    Ok, that makes sense. It is working on my sample sheet. When I apply the VBA code to my personal sheet, it does some really bizarre behavior. It's not updating the dates & times. My dates and times are between A35 and A47 with empty rows in between. Then, it puts the number 7 in cells from cell A49 all the way down to A4738. Not sure why it's doing that. I tried changing the one line in the VBA code lr = Range("A4").End(xlDown).Row to lr = Range("A35").End(xlDown).Row, and I changed this line - For Each cell In Range("A4:A" & lr) to For Each cell In Range("A35:A47" & lr). It's not working. Thanks for your help, much appreciated.
    Last edited by AliGW; 07-20-2023 at 09:03 AM. Reason: Please do NOT quote unnecessarily!

  16. #16
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: VBA: Auto update a weekly schedule

    Quote Originally Posted by Ltat42a View Post
    When I apply the VBA code to my personal sheet, it does some really bizarre behavior. It's not updating the dates & times.
    It could be that column A has many intermittent empty cells, so the last row starting from cell A4 downwards is only the last row of the contiguous range of cells, not necessarily the last row of column A.
    Due to the difference in your actual data compared to the original file, it is advisable to attach a new file with your actual data.

  17. #17
    Forum Contributor
    Join Date
    06-29-2005
    Location
    TN
    MS-Off Ver
    Microsoft 365
    Posts
    327

    Re: VBA: Auto update a weekly schedule

    Here it is, thank you
    Attached Files Attached Files

+ 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. Auto Create Daily Break Schedule from Weekly Work schedule
    By colema62 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-27-2021, 04:31 PM
  2. [SOLVED] how to auto update Weekly number?
    By noelcjf in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2020, 10:11 AM
  3. Auto update a weekly income
    By collectors in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-02-2018, 01:39 PM
  4. Weekly Employee Schedule auto fill day info
    By timmiller420 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-12-2016, 06:43 PM
  5. auto update weekly table basis status update
    By JJJ_1812 in forum Excel General
    Replies: 3
    Last Post: 04-28-2016, 03:38 AM
  6. auto populate weekly schedule from list
    By RGL_86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2016, 12:27 PM
  7. auto update of weekly report into another table layout
    By kelvinliowhc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-08-2014, 10:17 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