+ Reply to Thread
Results 1 to 7 of 7

automatically color code dates in week long chunks?

  1. #1
    Registered User
    Join Date
    03-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    automatically color code dates in week long chunks?

    Hello,

    I use a spreadsheet made by someone else at my office to track my hours at work. It automatically calculates overtime/weekend/holiday pay, which is handy. I use it by filling in the first column with dates (usually in sections mon-fri, but sometimes weekends too if I work them). I color code the weeks with three different colors (first listed week is Red, following week is Blue, third listed week is Yellow and then back to Red). I've been trying to figure out a way to have excel do this automatically but I'm not adept enough to figure this out. It seems that excel would have to look at the date, and determine if it belongs to the same 7 day week as the date above it. Then, if it DOES belong to the same week, use the same color as above, if if belongs to the following week, then use the next color in a given sequence. Could anyone advise on how this may be achieved? I'm pretty certain that excel does not have this feature built in, so it would have to be done via formula, or scripting, both of which I'll need pretty clear instructions on. Thanks in advance!

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: automatically color code dates in week long chunks?

    Could you post a sample of how you would expect such a worksheet to look?
    Thanks
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    03-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: automatically color code dates in week long chunks?

    I've attached a jpeg screenshot Hopefully I've done this correctly =)
    Attached Images Attached Images

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: automatically color code dates in week long chunks?

    Ok, this code will take a list of dates in column A starting at cell A3. It will go down the list to the last date and change the color based on Monday being the first day of the next week.

    Please Login or Register  to view this content.
    To use this, paste the above code in a standard module in the Visual Basic Editor. Then just run it.

    Let me know if that works, or if you want something else. I couldn't think of a way to do this without using code, though I suspect there might be a complicated way to do it.

  5. #5
    Registered User
    Join Date
    03-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: automatically color code dates in week long chunks?

    Wow, I can't believe you just whipped that up! Thanks a million. It seems to work fine, but requires that I manually run the macro when I want it to occur. Is there a way to have this always monitoring the A column so as I fill in dates it automatically changes the color?

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: automatically color code dates in week long chunks?

    Well, I could write something to look at the lowest date and if the font is black, evaluate what color it should be based upon your scheme.
    Let me know if that is what you prefer.

    It would be easiest to add this code to the worksheet:

    Please Login or Register  to view this content.
    This will recolor everything again including any changes you have made. It will always make the first week red. It runs whenever you change a cell in column A.

    You have to put this code in the Worksheet Change Event of the worksheet that contains your data. To do this, double click that Sheet in the "Microsoft Excel Objects" in the VBA Project Browser on the left side of the VBE. Above the main coding area there are two comboboxes. First change the left one to Worksheet, then change the right one to Change. Then paste the guts of the code above in.

  7. #7
    Registered User
    Join Date
    03-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: automatically color code dates in week long chunks?

    Works beautifully! Thanks a million davegugg!

+ 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