Abaixo segue como está o meu código atualmente.
Private Sub button_clean_Click()
register_id = ""
register_name = ""
register_address = ""
register_number = ""
register_bairro = ""
register_tel1 = ""
register_tel2 = ""
register_email = ""
register_note = ""
search_id = ""
search_name = ""
register_id.SetFocus
End Sub
Private Sub button_close_Click()
'Fechar cadastro de clientes e voltar pra Login
Unload REGISTER
Login.Show
End Sub
Private Sub button_delete_Click()
'Cliente não selecionado para excluir (ID e Nome)
If search_id.ListIndex = -1 And search_name.ListIndex = -1 Then
MsgBox "Selecione um cliente!", , "Nome da Empresa"
Exit Sub
Else
'Declarando variável da linha que será excluído
If search_id.ListIndex <> -1 And search_name.ListIndex = -1 Then
var_line_id = search_id.ListIndex + 2
Worksheets("BancoDeDados").Rows(var_line_id).Delete
MsgBox "Cliente excluído com sucesso!"
register_id = ""
register_name = ""
register_address = ""
register_number = ""
register_bairro = ""
register_tel1 = ""
register_tel2 = ""
register_email = ""
register_note = ""
search_id = ""
register_id.SetFocus
Exit Sub
Else
'Declarando variável da linha que será excluído
var_line_name = search_name.ListIndex + 2
Worksheets("BancoDeDados").Rows(var_line_name).Delete
MsgBox "Cliente excluído com sucesso!"
register_id = ""
register_name = ""
register_address = ""
register_number = ""
register_bairro = ""
register_tel1 = ""
register_tel2 = ""
register_email = ""
register_note = ""
search_name = ""
register_id.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub button_save_Click()
'Não salvar dados caso campos ID e Nome não seja preenchido
If register_id = "" Then
MsgBox "Por favor, insira o ID do cliente!", , "Nome da Empresa"
register_id.SetFocus
Exit Sub
Else
If register_name = "" Then
MsgBox "Por favor, insira o nome do cliente!", , "Nome da Empresa"
register_name.SetFocus
Exit Sub
Else
'Declarando variável que irá armazenar os dados
var_total_register = Sheets("BancoDeDados").Range("A" & Sheets("BancoDeDados").Rows.Count).End(xlUp).Row + 1
'Selecionando Planilha Banco de Dados
Worksheets("BancoDeDados").Select
'Gravação dos Dados
Cells(var_total_register, 1) = register_id
Cells(var_total_register, 2) = register_name
Cells(var_total_register, 3) = register_address
Cells(var_total_register, 4) = register_number
Cells(var_total_register, 5) = register_bairro
Cells(var_total_register, 6) = register_tel1
Cells(var_total_register, 7) = register_tel2
Cells(var_total_register, 8) = register_email
Cells(var_total_register, 9) = register_note
MsgBox "Dados gravados com sucesso!", , "Nome da Empresa"
register_id = ""
register_name = ""
register_address = ""
register_number = ""
register_bairro = ""
register_tel1 = ""
register_tel2 = ""
register_email = ""
register_note = ""
register_id.SetFocus
End If
End If
'Declarando variável para localização
var_search_id = Worksheets("BancoDeDados").UsedRange.Rows.Count
var_search_name = Worksheets("BancoDeDados").UsedRange.Rows.Count
'Configurando localização de clientes
search_id.RowSource = "BancoDeDados!a2:a" & var_search_id
search_name.RowSource = "BancoDeDados!b2:b" & var_search_name
End Sub
Private Sub register_address_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &HE0E0E0
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_bairro_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &HE0E0E0
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_email_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &HE0E0E0
register_note.BackColor = &H80000005
End Sub
Private Sub register_id_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &HE0E0E0
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_name_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &HE0E0E0
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_note_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &HE0E0E0
End Sub
Private Sub register_number_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &HE0E0E0
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_tel1_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &HE0E0E0
register_tel2.BackColor = &H80000005
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub register_tel2_Enter()
'&H00E0E0E0& cinza claro
'&H80000005& branco
register_id.BackColor = &H80000005
register_name.BackColor = &H80000005
register_address.BackColor = &H80000005
register_number.BackColor = &H80000005
register_bairro.BackColor = &H80000005
register_tel1.BackColor = &H80000005
register_tel2.BackColor = &HE0E0E0
register_email.BackColor = &H80000005
register_note.BackColor = &H80000005
End Sub
Private Sub search_id_Click()
Worksheets("BancoDeDados").Select
'Declarando variáveis para localizar pelo ID
var_total_search = Worksheets("BancoDeDados").UsedRange.Rows.Count
For s = 0 To var_total_search
If search_id.ListIndex = s Then
'Preenchendo os campos
register_id = Cells(s + 2, 1)
register_name = Cells(s + 2, 2)
register_address = Cells(s + 2, 3)
register_number = Cells(s + 2, 4)
register_bairro = Cells(s + 2, 5)
register_tel1 = Cells(s + 2, 6)
register_tel2 = Cells(s + 2, 7)
register_email = Cells(s + 2, 8)
register_note = Cells(s + 2, 9)
search_name = ""
End If
Next
End Sub
Private Sub search_id_DropButtonClick()
'Colocando ID em ordem crescente
search_name = ""
Ordenar_ID
End Sub
Private Sub search_name_Click()
Worksheets("BancoDeDados").Select
'Declarando variáveis para localizar pelo Nome
var_total_search = Worksheets("BancoDeDados").UsedRange.Rows.Count
For s = 0 To var_total_search
If search_name.ListIndex = s Then
'Preenchendo os campos
register_id = Cells(s + 2, 1)
register_name = Cells(s + 2, 2)
register_address = Cells(s + 2, 3)
register_number = Cells(s + 2, 4)
register_bairro = Cells(s + 2, 5)
register_tel1 = Cells(s + 2, 6)
register_tel2 = Cells(s + 2, 7)
register_email = Cells(s + 2, 8)
register_note = Cells(s + 2, 9)
search_id = ""
End If
Next
End Sub
Private Sub search_name_DropButtonClick()
'Colocando Nome em ordem crescente
search_id = ""
Ordenar_Nome
End Sub
Private Sub UserForm_Initialize()
'Declarando variável para mostrar os dados na localização
var_search_id = Worksheets("BancoDeDados").UsedRange.Rows.Count
var_search_name = Worksheets("BancoDeDados").UsedRange.Rows.Count
'Mostrando os dados da localização na inicialização
search_id.RowSource = "BancoDeDados!a2:a" & var_search_id
search_name.RowSource = "BancoDeDados!b2:b" & var_search_name
End Sub
Postado : 01/02/2016 11:29 am