+ Reply to Thread
Results 1 to 9 of 9

Trying to create 180 day sliding window centered on todays date

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Trying to create 180 day sliding window centered on todays date

    Hello,

    I am trying to create a sliding 180 day window centered on the current date (using columns for the date and rows for the cells to be calculated) that will slide left automatically as the date changes. Currently, I am manually changing my reference columns each day. The workbook is two sheets, one where the reference data is located and a second where I am displaying the results. I am new to the advanced functions of excel and have been searching for a solution online with no luck so far. The code I am using to manually move the window:
    Please Login or Register  to view this content.
    I have attached the workbook. Any help would be greatly appreciated.
    Thanks,
    Jim
    Attached Files Attached Files

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Trying to create 180 day sliding window centered on todays date

    if you can accept to modify your Function CountColor() as follow, it will count only those cells within 90 days of actual date. I commented the additional IF statement I inserted.
    Please Login or Register  to view this content.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Trying to create 180 day sliding window centered on todays date

    I appreciate the response. I don't really understand how to implement it though. I really am very new to the advanced functions of Excel. Is there any chance you can insert the correct code in my example workbook and re-post?
    Once again, thanks.

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Trying to create 180 day sliding window centered on todays date

    There you are.
    Notice that I changed the 4 formulas in the table so they refer to entire rows 5 and 6 respectively.
    The macro CountColor was changed to only count colored cells 90 days before today's date and 90 days after.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Trying to create 180 day sliding window centered on todays date

    This is great. I now understand more about the macro functions. The problem I am encountering now is that my actual worksheet is more complex than the example I uploaded. When I edit the "countcolor" macro in my other workbook the result cells show all zeros. The actual workbook is using a 365 day back and ahead for a 730 day total sliding window and is looking at 25 rows of data. I think the problem may lie in the offsets? Can you decode for me what this line of code is actually telling Excel to do?
    Please Login or Register  to view this content.
    The only part I understand is the > Now()-90 and the <Now() + 90.
    I really appreciate the help.

  6. #6
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Trying to create 180 day sliding window centered on todays date

    I figured it out. It works great now. I really appreciate the help.

  7. #7
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Trying to create 180 day sliding window centered on todays date

    One more question. Is there any way I can allow a color outside of this sliding window to be counted elsewhere? Example: I am tracking number of days inside the window, but I still want colors that are 400 days in the future to be counted elsewhere, not on a sliding scale. If I can't do this on the same sheet, does the macro apply to the whole workbook or can different sheets have a different macro for "countcolor"?

  8. #8
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Trying to create 180 day sliding window centered on todays date

    the following CountColor function is modified so it will accept optional parameters (PastDays and FutureDays). By default (if omitted) they are set up at 90 days. But you can specify them to be what you want like 0 day in the past and 400 in the future.

    But you still have the issue of counting cells within a sliding window although this window is now variable. If you want the original function, you can just change the name of this one and copy the old function back in place.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-20-2014
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Trying to create 180 day sliding window centered on todays date

    Great. Thank you very much. I appreciate the help.

+ 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. Sliding window analysis
    By biologist in forum Excel General
    Replies: 0
    Last Post: 09-22-2011, 11:25 AM
  2. Sliding Window Averaging function
    By carbonboywonder in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-22-2010, 05:36 AM
  3. Sliding window statistics
    By carbonboywonder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2009, 09:48 AM
  4. [SOLVED] Create a reference to a sheet that changes to todays date
    By Grd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-14-2006, 12:40 PM
  5. [SOLVED] Create a button that will date stamp todays date in a cell
    By Tom Meacham in forum Excel General
    Replies: 3
    Last Post: 01-10-2006, 09:10 PM

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