+ Reply to Thread
Results 1 to 5 of 5

Addition with IF statements

  1. #1
    Registered User
    Join Date
    10-13-2020
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    3

    Addition with IF statements

    Hi,

    I am having a problem with a formula in Excel.
    I have a file with product details, prices, etc.. Each row has a product and I have 1 column with prices in each cell. I want to add up all these prices, except for some of those. These products are optional.
    All optional items are labelled in the next row with a 1 for true and all other products are labbeled with 0.
    The issue is that I do not know how to translate the logic into a formula.

    Logic:
    For E1 to E90
    If Optional = 0 (false)
    add Ex to total price

    At the moment I am using the following code for a command:
    Please Login or Register  to view this content.
    Can I use a command that updates every time I update a value instead of clicking the button everytime?
    Can I change the code to incorporate changes in the amount of rows? If products get added, I need to update the code manually at the moment.

    I did not find similar problems using search, mostly because I did not know what to search for.

    Thanks!
    Last edited by MrWhistle; 10-13-2020 at 02:25 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Addition with IF statements

    You should be using the Worksheet Change event to trigger your Macro.

    Right Click On Your Sheet Name At the Bottom Of Excel and Select View Code
    Paste this code in the module that opens and close it.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    10-13-2020
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    3

    Re: Addition with IF statements

    First of all, thanks.

    I pasted your code and I think I understand what it does, but it does not work correctly for me.
    It should find the bottom row with a filled cell in column F. Then it puts the sum one row below that in column E, right?

    I get an error in this line:
    Please Login or Register  to view this content.
    The error states:
    -2147417848 (80010108)
    Method 'Value; of object 'Range' failed
    And then Excel crashes.
    Last edited by MrWhistle; 10-13-2020 at 01:43 PM.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Addition with IF statements

    This worked perfectly for me.

    Where did you paste the Macro?


    Right Click On Your Sheet Name At the Bottom Of Excel and Select View Code
    Paste this code in the module that opens and close it.

    Please Login or Register  to view this content.
    This also worked perfectly.

    Please Login or Register  to view this content.




    Maybe this version might be more stable:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 10-13-2020 at 02:20 PM.

  5. #5
    Registered User
    Join Date
    10-13-2020
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    3

    Re: Addition with IF statements

    The more stable version worked for me. I have no idea why the first version did not work. Thanks for helping me this well.

+ 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] If statements and Select statements in active controls userform
    By LaSouth1776 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-05-2020, 03:17 AM
  2. Formula with nested IF statements & AND statements
    By Hollywood44 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-11-2018, 03:38 PM
  3. IF Statements that incorporate addition
    By Spenserk in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-03-2014, 04:00 PM
  4. Reading If statements and formulating values from if statements
    By crnam in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-16-2013, 05:20 AM
  5. Multiple nested IF statements and AND statements
    By TonyGetz in forum Excel General
    Replies: 2
    Last Post: 12-14-2010, 03:07 AM
  6. Replies: 12
    Last Post: 05-15-2009, 08:38 AM
  7. [SOLVED] operator statements, shorting when reusing one of the statements?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2005, 02:05 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