Consulting

Results 1 to 11 of 11

Thread: Solved: If Statement, need help

  1. #1
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location

    Solved: If Statement, need help

    Hi there,
    I'd like to multiply the below by "G2" and then add "B2" the adding part is not the issue but can't get the multiplying part right!

    Please see example, is this a formula error? Close to giving up, please help.

    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2)) (works fine)
    But
    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>0,(G2*K2))+B2 (does not work)

    Please example, need to use G2 as a multiplier with K2 but can't get it right.
    Please help and thank you,...
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi Holland,

    You can't use K2 as an input in cell K2 - that creates a circular referrence.

    It seems to me the first part of your formula could be reduced to:
    =(B2>0)*(H2+I2)
    It's not clear what the desired result is, but I think you might get it with:
    =(B2>0)*(H2+I2)+(G2>0)*(H2+I2)+B2
    or:
    =(B2>0)*(H2+I2)+(G2>0)*(B2>0)*(H2+I2)+B2
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location
    Hi Paul,
    Thank you for the quick reply, but formula does not work. The key is to Multiply G2 (Time In Years) with "H2" and "I2" and then add "B2". Should be an If statement, I believe,.


    Example:
    If "A2" equals 100.00 and "H2 and I2" are both 10% after calculation you will have 120.00 but I want to Multiply "G2" with "H2 and I2" only so when "G2" equals 1 "K2" call will be 120.00 , if "G2" equals 2 "K2" cell will be 140.00, if "G2" equals 3 "K2" cell will be 160.00 and so on, etc,.

    Thanks agn,
    Holland

  4. #4
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    Try this:

    IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>0,(G2*B2*(H2+I2)))+B2
    I am a Newbie, soon to be a Guru

  5. #5
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location
    Hi Paul,
    Really close, see attached K2 should be 120 when G2= 0 or 1, if G2=2, K2 would = 140.00, if G2=3, K2 would = 160.0 etc,..


    Thank you for your help and assistance, just needs more tweaking.

    Holland
    Attached Files Attached Files

  6. #6
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    Well you need to us how do you calculate the Value in K2, if it is based on the same logic as you mentioned in the previous post, then K2 will be 160 when G2 is 2:

    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>1,(G2*B2*(H2+I2)))+B2

    If you still want K2 to be 140 when
    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>1,((G2-1)*B2*(H2+I2)))+B2 I am not sure still what is the logic behind the K2,but it does what you have asked for
    I am a Newbie, soon to be a Guru

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Holland
    formula does not work. The key is to Multiply G2 (Time In Years) with "H2" and "I2" and then add "B2". Should be an If statement, I believe,.

    Example:
    If "A2" equals 100.00 and "H2 and I2" are both 10% after calculation you will have 120.00 but I want to Multiply "G2" with "H2 and I2" only so when "G2" equals 1 "K2" call will be 120.00 , if "G2" equals 2 "K2" cell will be 140.00, if "G2" equals 3 "K2" cell will be 160.00 and so on, etc,.
    To get the 'right' formula you need to provide the 'right' specification. Try:
    =B2*((H2+I2)*G2+1)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location
    Quote Originally Posted by nepotist
    Well you need to us how do you calculate the Value in K2, if it is based on the same logic as you mentioned in the previous post, then K2 will be 160 when G2 is 2:

    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>1,(G2*B2*(H2+I2)))+B2

    If you still want K2 to be 140 when
    =IF(B2>0,(B2*I2))+IF(B2>0,(B2*H2))+IF(G2>1,((G2-1)*B2*(H2+I2)))+B2 I am not sure still what is the logic behind the K2,but it does what you have asked for
    nepotist
    Thank you very much, second formula works great and the If Statements account for G2 being "0" which still calculates correctly.

    Thank you again,
    Holland

  9. #9
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location
    Quote Originally Posted by macropod
    To get the 'right' formula you need to provide the 'right' specification. Try:
    =B2*((H2+I2)*G2+1)
    Hi Paul,
    This formula works as well thank you, need the If Statement though to account for the variable if the "0" is used.

    Thank you,
    Holland

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Holland
    This formula works as well thank you, need the If Statement though to account for the variable if the "0" is used.
    No, you don't need an IF test! Try:
    =B2*((H2+I2)*MAX(G2,1)+1)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  11. #11
    VBAX Regular
    Joined
    Oct 2008
    Posts
    41
    Location
    Quote Originally Posted by macropod
    No, you don't need an IF test! Try:
    =B2*((H2+I2)*MAX(G2,1)+1)
    Paul,
    Thank you this works amazing as well,

    Thank you agn,
    Holland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •