Closed Thread
Results 1 to 7 of 7

macro code to compare 2 cells

  1. #1
    Registered User
    Join Date
    03-07-2012
    Location
    jaipur
    MS-Off Ver
    Excel 2007
    Posts
    50

    macro code to compare 2 cells

    hi all i need a macro which will compare velues in 2 cells

    example if Cell A1 = 13:00 and B1 = 12:57 than

    cell C1 = color green

    please create a code for the above situation

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Thumbs up Re: macro code to compare 2 cells

    Hello kshitij_dch,

    Below is a code that should accomplish what you are trying to do. Place it in the worksheet it is meant for under the Worksheet_Change event.

    Just a note, if your values are formatted like 13:00, I needed to set the cell's number format to text to get the code to work correctly.
    Also the code only works if after you enter in a value into column B you hit the enter key. If you hit tab it will not work correctly. Please let me know if you would prefer to hit tab and I can adjust the code for you.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-07-2012
    Location
    jaipur
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: macro code to compare 2 cells

    thankyou for the reply i tell you the whole procedure , i have date in 24 hours format
    from 1 to 24 ....i need a macro which will check value in a column A compares with column B than after comparision result will be in column C

    column a 13:00 , column b 12:57
    column a 15:30 , column b 15:03

    that means it is acceptable for macro while checking 3 minutes prior and 3 minutes after the specified time in colum a . colour gets green in column c otherwise if above condition didnt meet color gets red in column c

  4. #4
    Registered User
    Join Date
    03-07-2012
    Location
    jaipur
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: macro code to compare 2 cells

    column A1 is 13:00 and column b1 is 12:57 column c will be green
    column a2 is 15:30 and column c1 is 15:32 column c will be green

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: macro code to compare 2 cells

    You do not need a macro for that. In the cells in column C, you are supposed to use a subtraction formula for to get the difference between the two times. Then you use conditional formatting on column C. Apply two conditions: One for the condition that the difference is less than or equal three minutes and one if otherwise. If you respond, please upload a workbook with your efforts if you can't get it to work.
    Ben Van Johnson

  6. #6
    Registered User
    Join Date
    03-07-2012
    Location
    jaipur
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: macro code to compare 2 cells

    work book attached for your reference , i d cell i have written the condition upon which macro will run

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: macro code to compare 2 cells

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed 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