VERSION 5.00 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Login Caption = "Login/Registo" ClientHeight = 3036 ClientLeft = 108 ClientTop = 456 ClientWidth = 4584 OleObjectBlob = "Login.frx":0000 StartUpPosition = 1 'CenterOwner End Attribute VB_Name = "Login" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub CommandButton1_Click() Dim ws As Worksheet Dim rng As Range Dim valorTextbox1 As String Dim valorTextbox2 As String Dim rng2 As Range Dim encontrado1 As Boolean Dim encontrado2 As Boolean Set ws = ThisWorkbook.Sheets("Registos") ' Defina o valor da ComboBox valorTextbox1 = TextBox1.Value valorTextbox2 = TextBox2.Value Set rng = ws.Range("A1:A67000") Set rng2 = ws.Range("B1:B67000") encontrado1 = False encontrado2 = False ' For Each cell In rng If cell.Value = valorTextbox1 Then encontrado1 = True Exit For End If Next cell For Each cell In rng2 If cell.Value = valorTextbox2 Then encontrado2 = True Exit For End If Next cell ' Mostrar mensagem com o resultado If encontrado1 = True And encontrado2 = True Then Unload Login Menu.Show Else MsgBox "Usuário inexistente." Unload Login Login.Show End If End Sub Private Sub CommandButton2_Click() Unload Login Registo.Show End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then ' Salva o workbook ThisWorkbook.Save ' Fecha o Excel Application.Quit End If End Sub