+ Reply to Thread
Results 1 to 15 of 15

VBA To Update Date and Clear Cells

  1. #1
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    VBA To Update Date and Clear Cells

    All,

    Attached is a spreadsheet to track FMLA hours for employees. I would like the calendar to keep track of any hours used for 365 days and then would like it removed. Someone helped me write a VBA which updates the month, makes it the next year and removes all data for that month. I need help changing it so it does it after 1 years time.
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    So what you want is a rolling 13-months. In other words. Since we are now in August 2016, you want to keep August 2015 and all months in between. So when September 1, 2016 arrives, I drop August 2015 and the calendar will run from September 2015 to September 2016 with September 2016 being the "working" month. Is this correct?
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    Yes, that was the best way I could think off unless you have another idea. The only other alternative would be for each day to clear after 365 days but that seems really complicated.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    I built this one on top of the old one. The old code is still there but not used.

    Here is how this one works. When you open the spreadsheet, it gets the current date and backs it up to the first of the month. It then compares that date to the date in cell A21. If it's the same month, nothing happens except for row 9. Suppose you last opened the book on Friday August 12th and today is now Tuesday August 16. The code will go through an clear all entries from August 1, 2015 to August 16, 2015. This keeps only 365 days of data in the calculations.

    September 1, 2016 comes around and now the date in Cell A21 is less than the first of September, so August 2015 goes away and everything is copied up one row. So September 2015 is now the top row. September 2016 is added as the last row. In addition, there is a check to see how many days are in September 2016 and the extra day (the 31st) is grayed out. These shadings get copied up each month.

    I notice how you have other pages in this workbook. I am not sure how the changes affect them.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    Dflak,

    We have been using your spreadsheet for a while now at it works perfectly!! What would I need to do to make it show 6 months into the future? We started to come across a lot of entries that are in the future that we would like to enter.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    I'll take a look. I got this in my "to do" bin.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    I think I got this.

    All the functionality is in the macro called Month_Shift.

    This macro checks cell A9 to see if it is more than a year out of date. If it is, it will shift everything up and then add a new line to the end. The new line will be six months from a year after the former value of cell A9. So if you skip a month or two, the application will catch up. In theory, it should catch up no matter what the start date in cell A9 is. So if you are saving this as a template with Aug 2015 as the date, run the application first, and then start data entry.

    After that it goes through and shades calendar dates that don’t exist like Feb 30th.

    Then it goes through and clears out dates older than same date last year. So if today were Aug 15, 2016, it would zero out all dates prior to Aug 5,2015.

    You may want to check the formulas in Cells R3 and R4. I don’t think they point to anything useful.

    I've done some QA on this and it seems to work. You might want to "wring it out."
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    Looks perfect and with the extra months we should now be able to do everything!

  9. #9
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    Dflak,

    If you are still around I could really use some help on this. You created the most recent spreadsheet for me in this conversation a couple months ago. It is supposed to automatically change months but it is not working. Any help would be greatly appreciated.

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    I downloaded the file from the link. I opened it up and it shows the dates from Aug 2015 to Feb 2017. That's not surprising since I have an on open workbook event.

    As a test, I changed the dates to start in July 2015 instead of August 2015 - this made it end in January 2017. Then I ran the macro and it shifted everything up and added February 2017.

    It appears to be working. This is what I think it is supposed to be doing.

    If it is not working for you, check to make sure you have the macros enabled.

  11. #11
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    I believe the original version your created for me would automatically adjust to keep 4 or 5 months into the future and older months with information would just drop off. If not I can just adjust the dates each time that should still work would just be really nice it happened automatically.

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    The way it is set up is to create one month into the future. I think it would be a relatively minor tweak to the code to go further into the future. How for would you like to go? If I ran the report today, what is the latest month you'd want to see?

  13. #13
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    About 5 or 6 months June would be perfect.

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: VBA To Update Date and Clear Cells

    I think this will do it for you. I've done almost no QA on this. I checked to see that the dates copied up, however, I suggest that you fill in some data and make sure they copy up too.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    08-01-2016
    Location
    OH
    MS-Off Ver
    2016
    Posts
    15

    Re: VBA To Update Date and Clear Cells

    Looks good thanks!

+ 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. [SOLVED] Clear multiple cells when a dropdown is changed and reset to today's date
    By GregHorn27 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-20-2015, 10:37 AM
  2. [SOLVED] Macro to clear certain cells in the row if first cells date is in the past
    By davorin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 04:19 AM
  3. [SOLVED] Macro to Clear contents in a range of cells when Date change.
    By aneshdas in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-08-2014, 01:53 AM
  4. [SOLVED] Adapt VBA code to clear the related cells instead of update
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2013, 05:50 AM
  5. Help adapting a macro to clear cells based on a date
    By nje in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-06-2013, 06:20 PM
  6. Update to week of X every week and clear cells
    By adamsurpren in forum Excel General
    Replies: 3
    Last Post: 06-12-2012, 07:32 AM
  7. Clear cells after certain date
    By rav295 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-13-2005, 04:35 AM

Tags for this Thread

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