+ Reply to Thread
Results 1 to 7 of 7

cell fill color update with date difference

  1. #1
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    cell fill color update with date difference

    im trying to make a workbook that updates the fill color of each row each day that it is opened based on the difference of the date in column O and the current date
    everytime it is opened it goes thru the range checks which row has the red fill color then update the no. of red fill color based on the date difference

    1. i cant get the correct no. of red fill color update for the row
    2. how can i make it also that it only update the fill color up to column N (if the date difference is greater that it will get past the column N)
    3. i manually put the fill color red on rows in column A, what is the best way to trigger automatically putting the current date on column O after putting the red fill color in column A?

    i have attached my workbook with the before and after

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by k1dr0ck; 06-29-2021 at 02:35 AM.

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: cell fill color update with date difference

    You ran out of resetting the variable i after Next cell.
    Corrected code in the attachment.
    Please Login or Register  to view this content.
    Comments:
    - don't keep this type of code in event procedures. Extract them into separate procedures in a standard module.
    - if you declare variables on one line, you should specify the type for each of them. Otherwise only the last one has a type defined by you and the rest is Variant.
    - if you are deleting lines in a loop, you have to do it in a loop with decreasing increment. Otherwise some lines may be omitted from checking.
    - solved the problem of coloring column A when the cell in column O was changed.

    Artik
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: cell fill color update with date difference

    hi, thanks for the reply and the comments

    sorry what I meant was after manually filling red color on column A it would trigger to auto input the current date on column O
    - solved the problem of coloring column A when the cell in column O was changed.

    i tried the file and it does not add the correct number of red fill color and I think its about the roundup date difference
    I found a way to actually get the "day difference" between two dates using DATEDIF as you can see below in the pic on column U but I don't know how to incorporate it into the code
    the number in column U is the red fill color that should be added in addition to the initial red fill color

    basically using the date difference:
    row 2 - should be 5 red fill colored (1+4)
    row 3 - correct 10 red fill colored (1+9)
    row 4 - should be 2 red fill colored (1+1)
    row 5 - correct 6 red fill colored (1+5)
    Attached Images Attached Images

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: cell fill color update with date difference

    Replace procedure to
    Please Login or Register  to view this content.
    Artik

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: cell fill color update with date difference

    thanks the fill color update now works correctly!

    so I tried editing the worksheet change section to insert date on column O after I manually fill colored a row in column A but I can't get it to work

    Please Login or Register  to view this content.
    tried also this but does not work

    Please Login or Register  to view this content.
    Last edited by k1dr0ck; 07-01-2021 at 03:12 AM.

  6. #6
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: cell fill color update with date difference

    Coloring cells alone does not trigger sheet events. Ie. I am familiar with two methods to force the event, but I wouldn't like to use them because they are a bit crazy.
    Or maybe change the philosophy of operation? Manually insert the date in the O column (using the keyboard shortcut Ctrl +; ) and the triggered event will color the cell in column A. But here comes another question. In the O column, you are satisfied with the date, or must there be a date and time? If the latter, the matter is a bit more complicated because you would have to use the following key sequence: Ctrl +; next Space and then Ctrl + Shift +: .
    The Worksheet_Change event will also be fired when you copy a previously prepared cell and paste into the cell in column A.
    Yet different. You can color the cell with the button macro. The selected cell is colored and the date is inserted in the O column.

    You have a couple of options. Now choose which way you want to go.

    Artik
    Last edited by Artik; 07-01-2021 at 04:00 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: cell fill color update with date difference

    thanks for the tip use a button and create a separate sub

    Please Login or Register  to view this content.
    Last edited by k1dr0ck; 07-03-2021 at 03:44 AM.

+ 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. Add date when I change color fill of a cell.
    By Throughstream in forum Excel General
    Replies: 2
    Last Post: 02-11-2019, 09:57 AM
  2. Replies: 5
    Last Post: 04-08-2016, 08:30 AM
  3. Replies: 6
    Last Post: 10-01-2015, 07:58 PM
  4. [SOLVED] Fill Cell Color based on start & end date.
    By hecgroups in forum Excel General
    Replies: 2
    Last Post: 10-04-2013, 10:14 AM
  5. Replies: 5
    Last Post: 11-04-2012, 07:59 PM
  6. [SOLVED] Update value in cell based on date and color row
    By abdulla1 in forum Excel General
    Replies: 0
    Last Post: 06-25-2012, 02:02 PM
  7. Color fill a cell and then remove the color when a date is added.
    By texas tornado in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2012, 02:14 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