+ Reply to Thread
Results 1 to 5 of 5

If then elseif statement not working.........

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    If then elseif statement not working.........

    I have the following code.....and its not working as expected.

    If user types in "n" for some reason the variable "ppm_input_error" is not getting set to true. Any ideas?

    Sub get_ppm_answer_from_user(ppm_answer As String, ppm_input_error As Boolean, msg_string As String)
    
        ppm_answer = Application.InputBox(msg_string)
        
        MsgBox ("ppm answer is *" & ppm_answer & "*")
        
        If ppm_answer = "" Then
            ppm_input_error = True
        ElseIf StrtDate = "False" Then
            ppm_input_error = True
        ElseIf ppm_answer = "Y" Or ppm_answer = "y" Or ppm_answer = "N" Or ppm_answer = "n" Then
            ppm_input_error = False
        ElseIf ppm_answer = "N" Or ppm_answer = "n" Then
            MsgBox ("in n")
            ppm_input_error = True             'ppm data not up to date
            MsgBox (ppm_input_error)
        Else: ppm_input_error = True
            MsgBox ("You have input incorrect text for this question.  It is assumed that the PPM data is NOT up to date.")
        End If
        
        
        MsgBox (ppm_input_error)
    End Sub

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: If then elseif statement not working.........

    found my mistakes......there were two of them.......



    Sub get_ppm_answer_from_user(ppm_answer As String, ppm_input_error As Boolean, msg_string As String)
    
        ppm_answer = Application.InputBox(msg_string)
        
        MsgBox ("ppm answer is *" & ppm_answer & "*")
        
        If ppm_answer = "" Then
            ppm_input_error = True
        ElseIf ppm_answer = "False" Then
            ppm_input_error = True
        ElseIf ppm_answer = "Y" Or ppm_answer = "y" Then
            ppm_input_error = False
        ElseIf ppm_answer = "N" Or ppm_answer = "n" Then
            MsgBox ("in n")
            ppm_input_error = True             'ppm data not up to date
            MsgBox (ppm_input_error)
        Else: ppm_input_error = True
            MsgBox ("You have input incorrect text for this question.  It is assumed that the PPM data is NOT up to date.")
        End If
        
        
        MsgBox (ppm_input_error)
    End Sub

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: If then elseif statement not working.........

    Hello Welchs101,

    You answered your question before I posted my answer. Good job on finding the problems.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: If then elseif statement not working.........

    Hey i was just going to reply to you with the mistakes, which you found yourself. Keep going.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: If then elseif statement not working.........

    I am going to mark this post solved since welchs101 is off line.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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