How to search 2 values in 2 distinct columns faster

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
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:
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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top