I'm creating a macro for a login screen that I'm developing to make excel a "database", the following code is to check if any "textbox" is empty, if the 2 "textboxes" are filled, the macro will check if there is a user whose name and password are connected, but the program crashes when i run it, is there a way to make the same code a lighter code?
Code:
Code:
VBA Code:
Private Sub bt_seguinte_Click()
Dim c As Long
usuario = tb_usuario.Value
senha = tb_senha.Value
lb_erro_usuario.Visible = False
lb_erro_senha.Visible = False
If Trim(usuario) = "" And Trim(senha) = "" Then
lb_erro_usuario.Visible = True
lb_erro_senha.Visible = True
ElseIf Trim(tb_usuario.Value) = "" Then
lb_erro_usuario.Visible = True
ElseIf Trim(tb_senha.Value) = "" Then
lb_erro_senha.Visible = True
Else
Application.ScreenUpdating = False
contar_usuarios = Rows(4).End(xlDown).Row
For c = 1 To contar_usuarios
Sheets("Usuários").Cells(1, 4).Offset(c).Select
Select Case True
Case ActiveCell = usuario
Exit For
Case ActiveCell = contar_usuarios And ActiveCell <> usuario
lb_erro_usuario.Visible = True
lb_erro_usuario.Caption = "*Usuário não encontrado"
Case ActiveCell <> usuario
End Select
Next c
If lb_erro_usuario.Caption <> "*Usuário não encontrado" Then
For c = 1 To contar_usuarios
Select Case True
Case ActiveCell = senha
Exit For
Case ActiveCell = contar_usuarios And ActiveCell <> senha
lb_erro_senha.Visible = True
lb_erro_senha.Caption = "*Senha ou Nome de Usuário incorretos"
Case ActiveCell <> senha
End Select
Next c
Else
End If
End If
Application.ScreenUpdating = True
End Sub