title: User login form for excel vba
body: <p>I am trying to create a login form where the username and password input match the data on a sheet. I tried to code for if either the username or password is wrong, it will show a msgbox and clear the input to redo. But when I tested that function, nothing happened. Picture here <a href="https://i.stack.imgur.com/CvvJf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CvvJf.png" alt="enter image description here"></a></p>
  
  <p>Code here</p>
  
  <pre><code>Private Sub login_Click()
  
      Dim x, a As Double
  
      a = WorksheetFunction.CountA(Range("A:A"))
  
      If untb.Value = "" Then
      MsgBox ("Enter the username"), vbOKOnly
  
      ElseIf passtb.Value = "" Then
      MsgBox ("Enter the password"), vbOKOnly
  
      ElseIf untb.Value &lt;&gt; "" And passtb.Value &lt;&gt; "" Then
  
      For x = 1 To a
  
      If untb.Value = Cells(x, 2) And passtb.Value = Cells(x, 3) Then
      Unload Me
      MsgBox ("Welcome to Great Wines :)"), vbOKOnly
      order.show
  
      End If
  
      Next x
  
      Else
      MsgBox ("Invalid username or password!"), vbOKOnly
      untb.Value = ""
      passtb.Value = ""
      untb.SetFocus
  
      End If
  
  
  End Sub
  </code></pre>