+ Reply to Thread
Results 1 to 14 of 14

Using IF THEN ELSE in Excel 2007

  1. #1
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Using IF THEN ELSE in Excel 2007

    I need to write a formula for the column I in an excel worksheet.

    For I4:

    IF(A4=A3 & A3=A2) then (I4= (220-(G2+G3+G4))/200) Else (I4=((220-G4)/220))

    Similarly,
    For I5:

    IF(A5=A4 & A4=A3& A3=A2) then (I5= (220-(G2+G3+G4+G5))/200) Else (I5=((220-G5)/220))

    and so on...

    Could you please provide the correct syntax to use this logic?

    Daymaker
    Last edited by daymaker; 06-20-2011 at 01:13 AM. Reason: Solved

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Using IF THEN ELSE in Excel 2007

    Here, try this in I5 and pull up and down:

    =(220-(COUNTIF($A$2:A5,A5)=COUNT($A$2:A5))*SUM($G$2:G4)-G5)/200

  3. #3
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    Quote Originally Posted by zbor View Post
    Here, try this in I5 and pull up and down:

    =(220-(COUNTIF($A$2:A5,A5)=COUNT($A$2:A5))*SUM($G$2:G4)-G5)/200


    This is not working

    May be if I attach the worksheet it will be helpful.

    I need to include one more constraint. Once the sum of the values in column F becomes 11, for a particular value in column A, then I want it to stop calculating. That's what the logic has to be.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Using IF THEN ELSE in Excel 2007

    Hi

    Maybe in I4
    =IF(AND(A4=3,A3=A2),(220-(G2+G3+G4)/200),(220/G4)/220)
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  5. #5
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    Hi Roger,
    Thanks a lot for the suggestion. This may work for I4. But do you feel it would work for all the data cells in the column F?

    Regards,
    Anshul

  6. #6
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Using IF THEN ELSE in Excel 2007

    Quote Originally Posted by daymaker View Post
    Hi Roger,
    Thanks a lot for the suggestion. This may work for I4. But do you feel it would work for all the data cells in the column F?

    Regards,
    Anshul
    Hi Anshul
    I don't see what column F has to do with it!
    Column F is not included in the calculation.

    If you mean all the cells down column I, then that will depend upon your data entered.
    To prevent seeing a #DIV/0 error when there are no values, amend the formula as below

    =IF(G4="","",IF(AND(A4=3,A3=A2),(220-(G2+G3+G4)/200),(220/G4)/220))

  7. #7
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    Hi Roger,
    I am including column F because it talks about the the number of resources. Anyways, that I can figure out. I think you're right. That shouldn't be included in the calculation. However, while calculating for I,
    it should take into account all the previous values in column G if they have identical values in column A. .

    Thanks & Regards,
    Anshul

  8. #8
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    I'll make the explanation a little more clear. I need to do some calculation in column I depending on the values in column G and Column A. When the values in Column A changes, it should directly use the formula as specified in Else statement.
    In other case, it should sum up all the values(current and previous data cell values) in column G for which the values in column A are identical. If the value in Column A change, it should use the Else formula.

    I need it starting from the data cell I3.
    Here's a rough explanation of the formula,
    For I3:
    IF(A3=A2) then (I3= (220-(G2+G3))/220) Else (I3=((220-G3)/220))

    For I4:

    IF(A4=A3 & A3=A2) then (I4= (220-(G2+G3+G4))/220) Else (I4=((220-G4)/220))

    Similarly,
    For I5:

    IF(A5=A4 & A4=A3& A3=A2) then (I5= (220-(G2+G3+G4+G5))/220) Else (I5=((220-G5)/220))

    and so on...

    Could you please provide the correct syntax to use this logic?

    Regards,
    Anshul

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Using IF THEN ELSE in Excel 2007

    And formula I write you above doesn't work? (Of coruse, if you put it where I write).
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    It worked now. I had by mistake used 200 instead of 220 at one place. Thanks a ton I really appreciate your help!

  11. #11
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Using IF THEN ELSE in Excel 2007

    Hi

    Then maybe
    =IF(G4="","",IF(COUNTIF($A$2:A4,A4)=ROW(A4)-1,(220-(SUM($G$2:G4)/200)),(220/G4)/220))

  12. #12
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Using IF THEN ELSE in Excel 2007

    Quote Originally Posted by Roger Govier View Post
    Hi

    Then maybe
    =IF(G4="","",IF(COUNTIF($A$2:A4,A4)=ROW(A4)-1,(220-(SUM($G$2:G4)/200)),(220/G4)/220))
    Sorry, that was rubbish!
    It should be
    =IF(G4="","",IF(COUNTIF($A$2:A4,A4)=ROW(A4)-1,(220-SUM($G$2:G4))/200,(220-G4)/220))

    However, I have just noticed that you are using Comboboxes on your sheet, not Data Validation dropdowns.

    As it stands, although it looks as though you are selecting numbers in Column A, the actual cells contain nothing, as there is no linked cell so the first part of the formula would always evaluate to False.

    The same applies to entries in columns C and Column E - you are using Combo boxes the wrong way.
    You would be better switching to Data Validation as I have in cells A2:A8 of the attached workbook. (I couldn't be bothered to make all of the changes)

    Then, as you change the selection in any of cells A2 to A8 you will see the result in column I alter accordingly.
    Attached Files Attached Files

  13. #13
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Using IF THEN ELSE in Excel 2007

    Roger, you could just change mine since it was already there
    Was problem in first cell that SUM should not refer to itself (G2)

    Also, I think it should refer to test F column if it's blank, not G.
    That's because in H you'll have DIV/0 if F is blank so it would be nicer to see...

    =IF(F2="","",(220-(COUNTIF($A$2:A2,A2)=COUNT($A$2:A2))*SUM($G1:G$1)-G2)/200)

  14. #14
    Registered User
    Join Date
    06-16-2011
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Using IF THEN ELSE in Excel 2007

    Thanks,
    I'm closing this thread.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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