+ Reply to Thread
Results 1 to 18 of 18

Mathematical code

  1. #1
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Mathematical code

    Hi,
    I have this code:
    =IF(AND(ISNUMBER(B7),ISNUMBER(B7)),B7+C7+D7+E7+F7,"")

    Instead of doing B7+C7+D7+E7+F7, is there some way to combine them.
    Thanks.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Mathematical code

    Perhaps.

    =IF(AND(ISNUMBER(B7),ISNUMBER(B7)),SUM(B7:F7),"")
    If posting code please use code tags, see here.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Mathematical code

    Why are there two identical ISNUMBER(B7) functions in and AND condition? What's the purpose?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Hi
    I am actually adding B7:F7 then minus G7. Can you edit the code? Thank you.

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    Try this:

    =IF(ISNUMBER(B7),SUM(B7:F7,-G7),"")

    Hope this helps.

    Pete

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Mathematical code

    how about =SUM(B7:F7)-G7
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  7. #7
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    this code is perfect =IF(ISNUMBER(B7),SUM(B7:F7,-G7),"")

    but how do I set the text when I get a negative in red font? example -2.

    thanks.

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    What do you mean by "set the text"? What do you want to happen if the answer is negative (or if B7 is negative - it's not clear what you mean).

    Pete

  9. #9
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Hi
    With this code:
    =IF(ISNUMBER(B6),SUM(B6:B7,-B8),"")

    Example:
    Carry over (B6) …. 2
    plus
    Received (B7)….. 5
    minus
    Processed (B8)….. 8
    The answer is: -1
    Then it should turn red.

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    One of the standard formats can be chosen to do that for you. Select the cell with the "answer" in it, then right-click and choose Format Cells | Number tab | Number, and then choose how you want negative numbers to be displayed (you can choose black or red, with or without the minus sign). Then click OK.

    You can use the Format Painter icon to copy that format to other cells.

    Hope this helps.

    Pete

  11. #11
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Can this be set in a conditional format?
    I want to keep my answer in black font but if I get a negative answer then it should answer red font.

    thanks.

  12. #12
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    There is no need to use Conditional Formatting - the instructions I gave you will do what you want.

    Pete

  13. #13
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Hi Pete,
    I did follow your instruction. I click the cell where the formula is then I right click and chose "number" then I selected the one with the red. But no matter what the answer is negative or no negative , it stay in same color.

    Is there no other way ?

  14. #14
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    You can use Conditional formatting if you wish to. Select the cell with the formula in (assumed to be B9 from the above), then click on Conditional Formatting | New Rule | Use a formula... , then put this formula in the dialogue box:

    =B9<0

    Then click on the Format button | Font tab and choose red from the Color drop-down, then OK your way out.

    Hope this helps.

    Pete

  15. #15
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Hi,
    I attached the file. It will work if I removed the color tab code in VBA code in sheet1. I want to keep the color tab code.

    Thank you.
    Last edited by RJ1969; 12-13-2018 at 04:08 PM.

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    I've set up the formatting for you in cells B9:G9 (and on other subtotal rows below), using normal formatting showing negative numbers in red with a leading zero, as described in Post #10.

    Hope this helps.

    Pete

    EDIT: It helps to attach the file:
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,716

    Re: Mathematical code

    Thank you Pete !!
    and thank you all.

  18. #18
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,703

    Re: Mathematical code

    I should have said "with a leading minus sign" in my previous post.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above and to the right of your first post in this thread, and mark this thread as SOLVED.

    Also, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ 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. Mathematical series
    By Creatives in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-12-2016, 01:18 AM
  2. Mathematical Table
    By Alcatraz_crysis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-13-2016, 03:19 PM
  3. [SOLVED] How do you get the X bar mathematical symbol?
    By TZ in forum Excel General
    Replies: 3
    Last Post: 10-28-2014, 12:27 PM
  4. mathematical function
    By oscar5 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-15-2013, 06:26 PM
  5. Hardness Conversion - mathematical code
    By Rdo556 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2011, 12:50 PM
  6. Mathematical Question
    By emanon132501 in forum Excel General
    Replies: 3
    Last Post: 06-10-2009, 11:42 AM
  7. Mathematical elimination
    By da_big_k in forum Excel General
    Replies: 0
    Last Post: 01-10-2006, 12:20 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