mercredi 29 août 2018

If Else not being recognized

I have a form in which the user inputs a number, and I want my macro to check whether the number exists in a specific list in order to do some stuff. Here's how I did it:

Private Sub CommandButton3_Click()
 Dim number As Integer, i As Integer
 For i = 10 To 10020
     If TextBox1.Value = Sheet1.Cells(i, 2).Value Then
         number = TextBox1.Value
     End If
 Next i
     MsgBox "A dica número " & TextBox1.Value & " não consta na lista.", vbOKOnly, "Dica não encontrada!"
     Exit Sub

 'Do the rest of the code here
End Sub

The thing is: no matter what number I input, the message box always comes up. number = TextBox1.Value is never read. I've tried manually checking if the values were the same for a specific input with message boxes, and even though they were the same, If/Else was never accessed.

Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire