+ Reply to Thread
Results 1 to 10 of 10

VBA code for comparing dates in column E and F, then highlight the date

  1. #1
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Exclamation VBA code for comparing dates in column E and F, then highlight the date

    Hello,

    I am new to the VBA programming.I need to code which compares dates from column E with respective date in column F then highlight green if date is greater and Red if date is lower. The code should stop on empty rows.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code for comparing dates in column E and F, then highlight the date

    Hi and welcome.

    Is there a reason you're looking for VBA to do this rather than just use conditional formatting?

    If this something you need to happen when you enter dates in a row, i.e. entering the date is the trigger? Or do you want to click a button when all the data is in and apply the highlight at that stage?

    BSB

  3. #3
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53
    Yes, I already have a macro written by someone, I need to make changes to it to accommodate this change to improvise.


    Quote Originally Posted by BadlySpelledBuoy View Post
    Hi and welcome.

    Is there a reason you're looking for VBA to do this rather than just use conditional formatting?

    If this something you need to happen when you enter dates in a row, i.e. entering the date is the trigger? Or do you want to click a button when all the data is in and apply the highlight at that stage?

    BSB

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: VBA code for comparing dates in column E and F, then highlight the date

    It might be useful if you attach a desensitized version of your workbook and include the macro you already have.
    It's often easier to add to what you have than start from scratch only to have you come back and ask if we can combine the two for you.

    To attach your workbook, click on "Go Advanced" below your reply then scroll down and click where it says "Manage Attachments" to open the upload window.

    BSB

  5. #5
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53
    Hello, i am afraid I can’t share the sheet here. I don’t have access to excel outside work. I can use that only in office and can’t login to external sites from office.
    If you could help me code these, I will combine myself. Basically, I want to understand how to name variable and write If loop here. Thanks in advance for your help.

    Quote Originally Posted by BadlySpelledBuoy View Post
    It might be useful if you attach a desensitized version of your workbook and include the macro you already have.
    It's often easier to add to what you have than start from scratch only to have you come back and ask if we can combine the two for you.

    To attach your workbook, click on "Go Advanced" below your reply then scroll down and click where it says "Manage Attachments" to open the upload window.

    BSB

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA code for comparing dates in column E and F, then highlight the date

    Possibly...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code for comparing dates in column E and F, then highlight the date

    Dangelor - Thank you so much, it seems working fine. Just one error, it is highlighting heading row as well, how to change it to skip headings. Also, Can you please help me understand what the below code does actually. Thanks in advance.

    lRow = Cells(Rows.Count, 5).End(xlUp).Row
    Set r = Range(Cells(1, 5), Cells(lRow, 5))

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA code for comparing dates in column E and F, then highlight the date

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-01-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA code for comparing dates in column E and F, then highlight the date

    This is perfect now, Thank you so much. I learnt how to end selection at last row and If statement.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code for comparing dates in column E and F, then highlight the date

    To cut down on typing.

    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. [SOLVED] Using VBA code to highlight row by comparing 2 dates (if one date is later than the other)
    By Bubbles_A in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 06-05-2018, 12:02 PM
  2. Replies: 3
    Last Post: 11-26-2014, 07:12 AM
  3. how to highlight dates prior to due date? Please help
    By ASIA30D in forum Excel General
    Replies: 8
    Last Post: 10-26-2013, 08:18 AM
  4. Replies: 5
    Last Post: 09-24-2012, 05:14 PM
  5. Replies: 1
    Last Post: 02-09-2012, 09:19 PM
  6. Excel 2007 : Comparing Dates in a Column
    By owhittle in forum Excel General
    Replies: 2
    Last Post: 07-01-2010, 05:43 AM
  7. Comparing Dates - Flawed Code?
    By br_turnbull in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2005, 11:05 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