+ Reply to Thread
Results 1 to 10 of 10

Conditional format based on Even/Odd????

  1. #1
    Registered User
    Join Date
    04-14-2007
    Location
    Phoenix AZ
    Posts
    32

    Conditional format based on Even/Odd????

    I want to be able to change the font color of the numbers in a column based on even or odd. I selected the columns and formated them to all be blue... thats the color I want for even, but now I can't figure out how to set a condition that checks for odd numbers and changes them to red.
    With previous help from forum members I now have a count of even/odd for all records, and even/odd for the last 30, this provided some very interesting results.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If you have numbers in A1:A100, select that range and use this formula in Conditional Formatting

    =MOD(A1,2)

    format as red

  3. #3
    Registered User
    Join Date
    04-14-2007
    Location
    Phoenix AZ
    Posts
    32
    Quote Originally Posted by daddylonglegs
    If you have numbers in A1:A100, select that range and use this formula in Conditional Formatting

    =MOD(A1,2)

    format as red
    I'm glad I asked this question... that formula doesn't work. I was using that formula to Count and return the total odd/even and got some "drastic results"! When I selected the column and gave this formula to conditional format wizard as a "formula is" condition it changed the font color for odds and evens for reasons I can't understand. ?????

    Please Login or Register  to view this content.
    This one works for a conditional column (odds), and this >

    Please Login or Register  to view this content.
    one works to count the total E's & O's.
    Last edited by farmerTom; 04-23-2007 at 11:10 PM.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by farmerTom
    I'm glad I asked this question... that formula doesn't work.
    Really?

    What sort of "numbers" do you have in your range? Assuming you have only integers in B1:B163 then if you select that range, with B1 active cell, and use the formula

    =MOD(B1,2)

    and apply red formatting then all your odd numbers will be highlighted in red. Do you want me to post an example spreadsheet?

  5. #5
    Registered User
    Join Date
    04-14-2007
    Location
    Phoenix AZ
    Posts
    32
    Quote Originally Posted by daddylonglegs
    Really?

    What sort of "numbers" do you have in your range? Assuming you have only integers in B1:B163 then if you select that range, with B1 active cell, and use the formula

    =MOD(B1,2)

    and apply red formatting then all your odd numbers will be highlighted in red. Do you want me to post an example spreadsheet?
    Excel Help Quote:
    MOD
    See Also

    Returns the remainder after number is divided by divisor. The result has the same sign as divisor.

    Syntax

    MOD(number,divisor)

    Number is the number for which you want to find the remainder.

    Divisor is the number by which you want to divide number.
    Any positive int. /2 will have a remainder of 1 if its odd, and 0 if its even.


    The formula
    Please Login or Register  to view this content.
    should have returned 0 or 1 in each cell but didn't. ?????????
    A couple of weeks ago I didn't know anything about Excel, now I know very little. The code with the the condition(<>) of doesn't equal zero worked right away. ?????
    Please Login or Register  to view this content.


  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    In your last post, you said that =(MOD(B1:B163,2)<>0)*1 worked fine. The *1 at the end implies that your numbers are stored as text, and you're multiplying by 1 to convert that data to numeric format.

    With that in mind, did you try the formula =MOD(B1:B163,2)*1 ?

    That will format all odd numbers.

    The "<>0" part, in this instance, is irrelevant. With just =MOD(B1:B163,2) you return a 0 for any even number and a 1 for any odd number in the range. To Excel, a 0 = False and 1 = True. So the conditional formatting will apply wherever the condition is true (1), meaning only on odd numbers.

    To conditionally format the even numbers in the list a different color, use =MOD(B1:B163,2)=0. (Or =(MOD(B1:B163,2)=0)*1 if your 'numbers' are textual.)

  7. #7
    Registered User
    Join Date
    04-14-2007
    Location
    Phoenix AZ
    Posts
    32
    I didn't format the cells as numbers... they are default / general. I may have done something else wrong too, I don't know enough and didn't check. When I re-make the spread sheet I'll import the data as numbers.

    0=False, and 1=True is boolean and I didn't think that Excel was treating this as a conditional answer, thats why I thought the <> were needed. And I can see that the formula
    Please Login or Register  to view this content.
    will test as True too. I'm starting to understand this a little better now.

    Thanks to all of you....

    Tom

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Hello farmerTom, I've suggested a simple working method twice now but I'm not sure you've implemented it as suggested.

    Let's be clear, you're using the formula within conditional formatting, right? Not on the worksheet?

    I never suggested using the formula

    =MOD(B1:B163,2)

    I suggested selecting the range B1:B163 and applying the formula

    =MOD(B1,2)

    If you do that the formula will automatically adjust for each cell in the range, so the condition will automatically adjust to =MOD(B10,2) in cell B10 or =MOD(B163,2) in B163.

    As you know, assuming the cell contains a positive integer, this formula will return a 1 if integer is odd or a zero if integer is even. 1 is effectively TRUE within CF and 0 is FALSE so this has the effect of formatting odd numbers, which is what you said you wanted to do, no?

    Using a formula like

    =MOD(B1:B163,2)

    in isolation is pointless, it may work in some circumstances but it's use betrays a lack of understanding of the results it gives. This formula returns an array but unless used within another function, e.g. SUM, you won't be assessing any value within it except the first.

    Note: it won't make any difference if the cells are formatted as number or text

    I've attached an example
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-14-2007
    Location
    Phoenix AZ
    Posts
    32
    daddylonglegs can I select the column because I add a row everyday, 6 days a week? I have to go through and change some of the funtions as is so I don't have to fill up all the formula everyday.

    Never mind tried it and it works ... thanks.

    Select column
    Open the Conditional format wizard
    Do formula is
    =MOD(B1,2)
    set format to red text
    works.

  10. #10
    Registered User
    Join Date
    02-14-2013
    Location
    London
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    15

    Re: Conditional format based on Even/Odd????

    Worked a Treat on my problem.

    =MOD($S10,2)

    With a $mark to cover an area rather than a single column

+ 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