Search code examples
excelvbainputboxmsgbox

VBA display MsgBox after InputBox


Messagebox not popping up after the inputbox.

Dim Output As Integer
Dim name As Variant
Output = MsgBox("Are You Interested in taking a short survey with me?", vbYesNo + vbQuestion, "Short Survey")
If Output = vbYes Then
MsgBox "Great! I'll guide you through this"
name = InputBox("First Question, What's your name?")
If name = vbYes Then
MsgBox "Welcome"
Else
End If
Else
MsgBox "Thanks! But you can try again if you change your mind"
End If
End Sub

Solution

  • Change If name = vbYes Then to If name <> "" Then

    When you input some text, variable name gets that text, not vbYes.

    Dim Output As Integer
    Dim name As Variant
    Output = MsgBox("Are You Interested in taking a short survey with me?", vbYesNo + vbQuestion, "Short Survey")
    If Output = vbYes Then
      MsgBox "Great! I'll guide you through this"
      name = InputBox("First Question, What's your name?")
      If name <> "" Then
        MsgBox "Welcome"
      End If
    Else
      MsgBox "Thanks! But you can try again if you change your mind"
    End If