+ Reply to Thread
Results 1 to 7 of 7

If statement w. Conditional formatting

  1. #1
    Registered User
    Join Date
    09-01-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2010
    Posts
    3

    If statement w. Conditional formatting

    I am trying to insert and IF statement with conditional formatting. I don't know if what I want to do is even possible, but here is what I'm looking for.

    I have two columns: Units per Case (say, A1) and Order Quantity (B1). I want to say If A1 is not divisible by B1, then turn the cell red. I have messed with this for a while and still can't seem to figure it out. Any help would be greatly appreciated!

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement w. Conditional formatting

    Use MOD to get remainder after division, and check for 0 remainder.

    e.g.

    =MOD(A1/B1,1)<>0

    will turn red if A1/B1 has a remainder other than 0
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    09-01-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: If statement w. Conditional formatting

    The formula seems to work, but then I try to do it for the entire column, it turns all the cells red. Is there a way to fix that?

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement w. Conditional formatting

    Try:

    =AND(A1<>"",B1<>"",MOD(A1/B1,1)<>0)

  5. #5
    Registered User
    Join Date
    09-01-2011
    Location
    Missouri
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: If statement w. Conditional formatting

    I got this to work when I played around with it:

    Select the first value in column A...say A2

    Select Conditional Formatting > New Rule > Formula
    Type =mod(A2/B2)>0 *Make sure the cells aren't absolute referenced ($A$2)
    Then just drag that formula to the end of the column, making sure to only copy the formula

    I tried multiple values and it worked for me.

  6. #6
    Registered User
    Join Date
    09-01-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: If statement w. Conditional formatting

    Yes, that seems to work. The only problem now is it turns it red for every value that does not equal one. Say the quantity is 12, any number other than 12 turns the cell red. I want it so that any number NOT divisible by 12 turns the cell red, and any number that is divisible by 12 will keep it clear.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement w. Conditional formatting

    Did you try 24, 36, 48? They should not turn red when quantity is 12.. i tested it to be true.

    This is assuming the quantity is column B (so 12 is in column B, 24, 36, 48 in column A).

+ 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