+ Reply to Thread
Results 1 to 19 of 19

Conditional Formatting with VBA

  1. #1
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Conditional Formatting with VBA

    Hello, I would like help with a Macro that would format a row based on the following:

    Color the entire row RED (font color: White) if any cell in Column 1 = “Active” AND Due Date is 6 months away from TODAY().

    Stay RED (font color: White) until any cell in Column 1 changes to Inactive (or any other text or blank) or Due Data changes to a date further than 6 months away from TODAY().

    Thank you for your help!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    Which column is "Due Date"?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    Hello Leith Ross, thanks for the reply.

    Due Date is in Column N.

    Also, right now there are 837 records (rows) but more will be added with time.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    Do you want this to happen as the data is entered into column "A" or run a macro to format all the data at one time?

  5. #5
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    Hi Leith Ross,

    If possible it would be nice to format the row as a new row is entered, text in column "A" changes from Active to any other text or Due Date (column "N") changes to a date further than 6 months away from TODAY().

    If that's not possible than running the Maco to format all the data at one time is fine.

    Thanks!

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    Add a new VBA module to your workbook. Copy and paste the macro code below into it.

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    I will write another macro to format the data as it is entered.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    This macro can be copied into any worksheet module. This will format the row as the data is entered.

    Please Login or Register  to view this content.
    How to Paste a Macro into a Worksheet
    1. Copy the macro with Ctrl+C.
    2. Right Click the Sheet Tab at the bottom of the worksheet.
    3. Click View Code
    4. Paste the macro into the module with Ctrl+V.
    5. Save the macro using Ctrl+S

  9. #9
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    Thank you. I did was you told me.

    After I saved it nothing happened. For example, there's an expiration date (cell N837) of 8/24/2015 (that's within 6 months from TODAY()) and cell A837 is "Active" but the row did not turn RED. What do I have to do to run the code in the Module? Sorry I'm new with VBA. Thanks!

  10. #10
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    Thank you. I did was you told me.

    After I saved it nothing happened. For example, there's an expiration date (cell N837) of 8/24/2015 (that's within 6 months from TODAY()) and cell A837 is "Active" but the row did not turn RED. What do I have to do to run the code in the Module? Sorry I'm new with VBA. Thanks!

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    I have tested this macro and it works. Be careful of your dates. They need to be in day/month/year format.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    Thanks. I checked and the dates in column N are in the correct format.

    I would also like to mention that I have this Macro in ThisWorkbook

    Please Login or Register  to view this content.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    Your macro is checking column "N" is equal to today's date. If it is then the word "six" is added to the email body.

    What is your question?

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    Your macro is checking column "N" is equal to today's date. If it is then the word "six" is added to the email body.

    What is your question?

  15. #15
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    I apologize. I really didn't have a question on my last reply.

    If you don't mind could you revise the attached file. The actual data has been replaced for security reasons. I'm hoping that if you take a look at the file you can tell me why the module does not run. I'm sure the code is fine. It may be something I'm doing wrong. Thanks! Clinical Contracts_ Format.xlsm

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    I don't know if you are having problems connecting with the forum, but I am. I did get your workbook and am looking at it.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    I don't know if you are having problems connecting with the forum, but I am. I did get your workbook and am looking at it.

  18. #18
    Registered User
    Join Date
    05-12-2015
    Location
    Miami, FL
    MS-Off Ver
    365
    Posts
    49

    Re: Conditional Formatting with VBA

    I was having problems earlier. But it seems to work fine now. Thanks.

  19. #19
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Conditional Formatting with VBA

    Hello onelifestyle,

    No problem, the code needed to be moved from Module1 to Sheet1. The attached workbook works like you want now.
    Attached Files Attached Files

+ 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. Formatting Cells with Date or Text Values in a Conditional Formatting Formula
    By Phil Hageman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2014, 09:36 AM
  2. Opening xlsm files with conditional formatting opens with removed conditional formatting
    By Martijn.Steenbakker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2014, 05:38 AM
  3. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  4. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  5. Replies: 3
    Last Post: 05-15-2012, 04:13 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