vendredi 14 février 2020

VBA/Excel If statement is ignored (even if it is true), and Always executes Else

Any help will be greatly appreciated, as I am very new to VBA in Excel. Here's a snippet of my code:

Private Sub CheckPCButton_Click()                                                                      
    Dim totRows As Long, i As Long
    totRows = Worksheets("Sheet4").Range("A1").CurrentRegion.Rows.Count

    For i = 2 To totRows
        If Trim(UCase(Sheet4.Cells(i, 1))) = Trim(UCase(TextBox22.Text)) Then           
            TextBox22.Text = Sheet4.Cells(i, 1)
            TextBox25.Text = Sheet4.Cells(i, 2)
            TextBox24.Text = Sheet4.Cells(i, 3)
            TextBox23.Text = "Approved"
        Else
            MsgBox "Not approved"

            Exit For
        End If 
    Next i

End Sub

Aucun commentaire:

Enregistrer un commentaire