Consulting

Results 1 to 16 of 16

Thread: Solved: IF Statement Limit Reached

  1. #1

    Solved: IF Statement Limit Reached

    Hi all,

    I have a formula that may have reached the limit for IF statements. Does VBA allow more IF statements per cell?

    The first IF is getting rid of a Value Error

    If so...can someone suggest code for:

    This formula is in CELL E13

    =IF(F13=" "," ",IF(OR(BY15="1",BY15="2"),EA14,IF(BY15="3",CG16,IF(BY15="4",CG17,IF(BY15=" 5",CQ16,IF(BY15="6",CQ17,IF(BY15="7",CQ18,IF(BY15="8",DC14,IF(BY15="9",DO14 ,))))))))

    Thanks much

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Yep your over the limit. 7 is the limit. I counted 9. As far as correcting the formula, XLD is the man. Hope he comes by to assist (no disrrespect to any of my other fellow VBA pals).
    Peace of mind is found in some of the strangest places.

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    You might want to consider Select Case as in this example:

    [vba]
    Select Case < Expression to test> Case Do something
    Case Else Do something else
    End Select[/vba]

    Also give this link a look

    http://www.ozgrid.com/VBA/select-case.htm
    Peace of mind is found in some of the strangest places.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have a look here
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Forgot about ole Chip Malcomb.
    Peace of mind is found in some of the strangest places.

  6. #6
    Ok..im learning..great ideas..one more thing....how do I assign this case statement to a cell like a formula? The formula im replacing is in E13. This will work only when I run the SUB.

    [VBA]
    Sub Candyman1()
    Select Case Range("BY15").Value
    Case "A"
    Range("E14").Value = Range("CG16").Value
    Case "B"
    Range("E14").Value = Range("CG17").Value
    Case "C"
    Range("E14").Value = Range("CR16").Value
    Case "D"
    Range("E14").Value = Range("CR17").Value
    Case "E"
    Range("E14").Value = Range("CR18").Value
    End Select
    End Sub

    [/VBA]

  7. #7
    Also..can a case be a fromula? Like an If/and? See below..thanks for all the help in advance.

    [vba]
    Sub Candyman1()
    Select Case Range("BY15").Value
    Case "A"
    Range("E14").Value = Range("CG16").Value
    Case "B"
    Range("E14").Value = Range("CG17").Value
    Case "C"
    Range("E14").Value = Range("CR16").Value
    Case "D"
    Range("E14").Value = Range("CR17").Value
    Case "E"
    Range("E14").Value = Range("CR18").Value
    Case ' IF(AND(F13>=24,BY15<>"E")
    Range("E14").Value = "MESSAGE HERE"
    End Select
    End Sub

    [/vba]

  8. #8
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Perhaps a UDF?
    Peace of mind is found in some of the strangest places.

  9. #9
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    You can put If's under a Case statement
    Peace of mind is found in some of the strangest places.

  10. #10
    UDF?

    Ok so If statements cant go in a case statement.

    My other question is looking at code below..when the value in cell BY15 changes, the value in E14 should change if it equals one of the case statments. This code doest cause a change unless I run the sub candyman. BY15 is linked to a drop down list..not sure if thats the problem. Think im explaining that right.

    Sub Candyman1()
    Select Case Range("BY15").Value
    Case "A"
    Range("E14").Value = Range("CG16").Value
    Case "B"
    Range("E14").Value = Range("CG17").Value
    Case "C"
    Range("E14").Value = Range("CR16").Value
    Case "D"
    Range("E14").Value = Range("CR17").Value

    End Select
    End Sub

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Gimli,
    These things are easier if you provide a small sample file.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    ok md..ill post tommorow

    thanks much

  13. #13
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Im thinking worksheet change event
    Peace of mind is found in some of the strangest places.

  14. #14
    Hi,

    Ok..attached is a sample. I have a drop down box that changes the cell value but the sub candyman1 wont run when value is changed via drop down box.

    If I type in the value it works... Can this be set up so the drop down selection fires the sub candyman1?

    Also can I put mutible calls? See code....

    thanks so much

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Use the events available to the combobox eg
    [VBA]
    Private Sub ComboBox1_Change()
    Call Candyman1
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    All to easy

    thanks much

Posting Permissions

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