+ Reply to Thread
Results 1 to 17 of 17

Update the date, but not everyday

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Update the date, but not everyday

    This would seem like something so many people would want, I'm very surprised that, after scouring the internet, I couldn't find anything that adresses this issue. First of all, I'm totally inexperienced with VBA, but I'm experienced in C, C++, MATLAB and the like, so don't worry about scaring me with tech, I'm simply trying to figure out how to do this without first spending weeks or months learning VBA on my own before attempting to implement this.

    So, what I am trying to do is have, on a single spreadsheet, a list of tasks with due dates, however, the due dates change. They change because after a due date has passed, you have a new due date. I don't want to have pages and pages of task sheets, just one task sheet, and I don't want to manually change the due dates every week or every month, etc. I want to, once I enter in a start date, all these due dates will automatically update to the next due date based on if today's date has surpassed the due date. It will compile all the different tasks in this program, some are due weekly, some are due once every other week, others monthly, some quarterly, and other annually. They will all be on the same task sheet and once the due date has passed, the value in the "Due Date" cell will need to change to a new due date. I included a picture to give you an idea of the template. Don't worry about the conditional formatting, I have that already figured out. All I'm concerned with is having the due date replaced by a new value once today's date has passed the due date. Thanks! Screen Shot 2012-10-25 at 3.41.18 PM.jpg

  2. #2
    Valued Forum Contributor
    Join Date
    08-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    573

    Re: Update the date, but not everyday

    You can try code in this structure,
    Please Login or Register  to view this content.
    Date returns today's date.

  3. #3
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Ok, I'll try something like that. I might have to suck it up and spend a few weeks learning how to code in VBA in order to make this work. I'll need to code for each individual cell, I can't use an iterative "For" because I won't be grouping weekly or monthly tasks together, they'll be grouped by what system they're associated with instead. Thanks!

  4. #4
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Ok, I have another question for you guys. I set a workbook open event so that this code will execute anytime the workbook opens. The only problem is that the VBA editor/debugger opens every time I open excel. This happens if I do it using Auto_Open subroutine and if I put the code in the private module. The code works, it just opens the editor/debugger, but it doesn't indicate any problems with the code or give me any errors, it just opens is like a pop-up. The code I'm using in the private module is as follows:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    The Workbook_Open event should be in ThisWorkbook Module.

    Change the code to
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    It was in the ThisWorkbook Module. From what I understand, that is what is meant by "private module" nowadays. However, it didn't stop the problem. I removed the code, and surely enough, it didn't automatically open it, but when I run my "Macro1" macro manually, it also automatically pops up the editor, yet gives me no errors or reason why it would open the editor. So perhaps it's the Macro1 code that's causing the editor to pop up. Here's my code for the Macro

    Please Login or Register  to view this content.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    With this code in ThisWorkbook
    Please Login or Register  to view this content.
    and this code in a General Module
    Please Login or Register  to view this content.
    The workbook opens and changes Cells(2,5) of Sheet1 (and does not open the VBA Editor).

  8. #8
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    That works beautifully! Was it the "." before the "Cells" or the "with" statement that fixed it you think? I've never seen a "with" statement before with C++, so I had to look up what it does after you posted that.

    Anyway, I have one last question and I think I'm done here. I'd like to see if I could get this macro to run automatically once a day without having to use task scheduler. I looked at some forums, namely here at the link provided, but their advice didn't seem to help. Any ideas? http://www.pcreview.co.uk/forums/run...y-t940041.html

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    Regarding this
    Was it the "." before the "Cells" or the "with" statement that fixed it you think?
    Your code didn't specify what worksheet the code should run on...I suspect that was the issue. The . before Cells merely ties the Cells to Sheet1.

    Regarding this
    Please Login or Register  to view this content.
    The only way I'm familiar with to do this is to leave the Workbook open at all times and create an OnTime procedure to run the code every 24 hours. There are ways to open excel with Batch Files such that it can be scheduled to open. However, I'd assume you'd have to respond to "Allow Macros" unless you set Security to Low. Not a good idea.

  10. #10
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Well, hopefully the brutes known as users will understand that they'll have to close and reopen this every time. Thanks for the help!!

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    I made a misstatement here
    leave the Workbook open at all times
    Tell me what you wish to do...perhaps we can think it through.

  12. #12
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Well, the problem is that the users might leave the workbook open at all times, and they might not. So, I'd like to cover both grounds, have it check for the need to update every time it opens, and also check for updating once a day just in case they never close it. Some of these guys are really smart, and some of them....well, let's just say some didn't know how to use a mouse before starting this job. So instructing them on how to set it up in task scheduler doesn't seem plausible. I just want to send them this spreadsheet and say "here, use this, put in the completion dates and email me an updated copy every week". If I could do that without introducing a serious computer vulnerability, that would be awesome.

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    Let me play with it a bit...what time would you like the procedure to run...like 1:00 AM?

  14. #14
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    The time is irrelevant. 1AM is good, anytime shortly after midnight is fine. Thanks!

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    I'm unable to make this work without getting the Enable Macros message. If the Workbook IS open then the procedure will execute as desired.

    You may wish to start a new Thread with this issue.

  16. #16
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Quote Originally Posted by jaslake View Post
    If the Workbook IS open then the procedure will execute as desired.
    I'm confused. Were you able to get it to work only while workbook is open BUT you had to enable macros? I don't need this to run while the workbook is closed. I just need it to run whenever the workbook is manually opened and just in case the workbook is left open. If I have to enable macros to do that, just let me look at the code, and I'll consider it. Thanks, John!

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    This code is in the attached.

    In ThisWorkbook
    Please Login or Register  to view this content.
    In a General Module
    Please Login or Register  to view this content.
    The code will run Macro1 upon opening the Workbook and then schedule Macro1 to run at 1:00 AM each day until the Workbook is closed. It does this repeatedly...let me know of issues.
    Attached Files Attached Files
    Last edited by jaslake; 10-26-2012 at 03:30 PM.

  18. #18
    Registered User
    Join Date
    10-25-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Update the date, but not everyday

    Thanks, I'll mark this solved, but how do you test the timer code besides waiting until 1AM? I tried several times to change the time to a few minutes later, but the data doesn't update.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Update the date, but not everyday

    Hi jdnels81

    When you
    I tried several times to change the time to a few minutes later
    Did it "Beep"? If it did the code executed. The code won't update unless
    Please Login or Register  to view this content.

+ 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