+ Reply to Thread
Results 1 to 2 of 2

Using a macro to create a conditional format based on a date in a cell

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    19

    Smile Using a macro to create a conditional format based on a date in a cell

    I am currently using the conditional formatting function in excel for a spreadsheet. I would like to create a macro that will do the same thing as the spreadsheet is getting too large. My current conditional formatting is as follows:

    Format only cells that contain blanks: no format set - stop if true (if the cell in column A is blank than do not format. Stop if true)
    Format only cells that contain non blanks: no format set - stop if true (if a the cell in column B is not blank than do not format. Stop if true)
    Formula: =IF($B$2:$B$2651="",$A$2:$A$2651<=TODAY()) (If a cell in column B is blank than format the cell in column A if the cell in column A meets the following criteria: If the date is today or prior to today highlight cell in colmn A red)

    I need a macro to do the same thing:

    Do not format if the cell in column A if the cell in column A is blank.
    Do not format if the cell in column A if the cell in column B is not blank.
    Format column A if: a cell in column B is blank and the date in column A is today or prior to today than highlight the cell in column A red.
    Do not format the cell in column A if the date in the cell in column A is later than today.
    (there should be no formatting in column B at all no matter what. I just want to format the cell in Column A based on the criteria of the cell in column A and column B).

    So, basically I have a spreadsheet that has a forecast date in column A. There may or may not be a date in the cell in column B. Column B is the day the task was actualized.

    I want to highlight the forecast date in column A if it is today or past due. If a the task is actualized in column B than there is no need for any formatting.

    Thank you for your help on this. I know the macro should be pretty easy but I am not familiar with writing macros so it is a bit difficult for me. My spreadsheet has 2651 rows of data and each row has a column with a forecast and an actual date. There are 565 columns. Lots of data to review. I want past due forecast dates to be highlighted in red so it stands out easily.
    Attached Files Attached Files
    Last edited by srsev; 12-11-2012 at 11:30 PM. Reason: Added an attachment

  2. #2
    Registered User
    Join Date
    07-03-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Using a macro to create a conditional format based on a date in a cell

    I was finally able to put in a conditional formatting for dates listed as today and prior to today. Unfortunately it is not skipping blanks. Does anyone know how to rewrite the following code to skip blank cells?

    Sub Macro1()
    Range("AF4:AF2846").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=INT(AF4:AF2846)<=TODAY()"
    Selection.FormatConditions(1).Interior.ColorIndex = 3
    FinalRow = Range("AF4:AF2846").End(xlUp).Row

    End Sub

+ 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