View Full Version : Solved: IF/ ELSEIF Help
gimli
04-26-2010, 04:09 AM
Hi all,
 
The below code works ok up until the last elseif.  Im trying to blank a cell out if the value of F13 is 0.  F13 has data validation of 0 - 45.  So F13 is always 0 until someone enters another number.  Any ideas?
 
thanks mucho grande
 
 
 
Sub Angelina()
    If Range("F13") >= 24 And Range("BX15") <> "A" Then
       Range("E13") = "A ONLY"
    
    ElseIf Range("BX$15") = "A" Then
        Range("E13") = Range("$CF$16")
    
    ElseIf Range("BX$15") = "B" Then
        Range("E13") = Range("$CF$17")
    
    ElseIf Range("BX$15") = "2" Then
        Range("E13") = Range("$CQ$16")
    
    ElseIf Range("BX$15") = "3" Then
        Range("E13") = Range("$CQ$17")
    
    ElseIf Range("BX$15") = "4" Then
        Range("E13") = Range("$CQ$18")
    
    ElseIf Range("BX$15") = "N" Then
        Range("E13") = Range("$DC$14")
    
    ElseIf Range("F13") = 0 Then
        Range("E13") = " "
    End If
End Sub
Bob Phillips
04-26-2010, 04:14 AM
What's in BX15?
gimli
04-26-2010, 04:25 AM
BX15 =
 
A
B
2
3
4
N
 
Populated by a drop down box selection
gimli
04-26-2010, 04:48 AM
Heres a file.  This example also wont populate a space if cell value = 0
 
Not the example above but same result.
I have not looked at the attachment yet, but what do you mean by not working for the last ElseIf?  If the conditions are met, it enters a space in E13.  If you want the cell to be blank, ditch (delete) the space you have between the quote marks, or, use ClearContents.
        Range("E13") = ""
        'or
        Range("E13").ClearContents
Does that help?
 
Mark
Bob Phillips
04-26-2010, 05:21 AM
What are you on about? What does thread #4 have to do with the original question, and your answer in #3 doesn't tell me what is in BX15, just the options available.
gimli
04-26-2010, 05:55 AM
Xid,
 
Sorry for confusion...to answer your first question..bx15 contains A.
 
The second post was a different example with the same problem. Thought it would help to post a file.
gimli
04-26-2010, 06:02 AM
GTO,
 
basically if the conditions in the statement arent met I want to put a blank space in cell E13.  Your suggestions didnt do it...probably a logic problem with my brain :-)
Unless I am missing something, the only time that the last ElseIf will execute is if there is nothing in BX15 AND F13 = 0
 
To reiterate, if any of the choices available to BX15 have been made, you already have executed one of the preceeding ElseIf's.
 
If I leave BX15 blank, and put a zero in F13, it does execute the last ElseIf.
 
Is that the same for you?
 
Mark
gimli
04-26-2010, 06:22 AM
GTO,
 
Yes your right... Now I see whats happening. The condtion is met thus populating the cell before it gets to the end. :banghead: 
 
Guess what im trying to do is add something that if cell F13 = 0 AND BX15 = A..populate E13 with a blank space....see posted code.
 
Basically, upon opening the worksheet the default selection will be A and cell F13 will = 0. So I want cell E13 with a blank space.
 
 
Sub Angelina() 
If Range("F13") >= 24 And Range("BX15") <> "A" Then 
Range("E13") = "A ONLY" 
 
ElseIf Range("BX$15") = "A" Then 
Range("E13") = Range("$CF$16") 
 
ElseIf Range("BX$15") = "B" Then 
Range("E13") = Range("$CF$17") 
 
ElseIf Range("BX$15") = "2" Then 
Range("E13") = Range("$CQ$16") 
 
ElseIf Range("BX$15") = "3" Then 
Range("E13") = Range("$CQ$17") 
 
ElseIf Range("BX$15") = "4" Then 
Range("E13") = Range("$CQ$18") 
 
ElseIf Range("BX$15") = "N" Then 
Range("E13") = Range("$DC$14") 
 
ElseIf Range("F13") = 0 Then 
Range("E13") = " " 
End If 
End Sub
gimli
04-26-2010, 06:40 AM
Ok..this does it.  Thanks for the help all. Now I understand IF's a bit better...
 
 
 
Sub Angelina() 
    If Range("BX$15") = "A" And Range("F13") = 0 Then
        Range("E13") = " "
 
    elseIf Range("F13") >= 24 And Range("BX15") <> "A" Then 
        Range("E13") = "A ONLY" 
         
    ElseIf Range("BX$15") = "A" Then 
        Range("E13") = Range("$CF$16") 
         
    ElseIf Range("BX$15") = "B" Then 
        Range("E13") = Range("$CF$17") 
         
    ElseIf Range("BX$15") = "2" Then 
        Range("E13") = Range("$CQ$16") 
         
    ElseIf Range("BX$15") = "3" Then 
        Range("E13") = Range("$CQ$17") 
         
    ElseIf Range("BX$15") = "4" Then 
        Range("E13") = Range("$CQ$18") 
         
    ElseIf Range("BX$15") = "N" Then 
        Range("E13") = Range("$DC$14") 
         
    ElseIf Range("F13") = 0 Then 
        Range("E13") = " " 
    End If 
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.