Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#64113
Oi!
Fiz essa rotina para cadastrar em uma outra planilha:
Código: Selecionar todos
Sheets("Cadastrar").Range("A3:L3").Copy
        Sheets("Bco_Padrinhos").Select
        Call LinhaVazia
        Selection.PasteSpecial Paste:=xlPasteValues
        Selection.End(xlUp).Select
        Sheets("Cadastrar").Select
        Range("B2:L2").ClearContents
        ActiveWorkbook.RefreshAll
        ActiveWorkbook.Save
        MsgBox "Cadastro realizado com sucesso!", vbInformation, ""
Ela funciona perfeitamente como quero. Contudo, quando adicionei todo o restante do tratamento somente a essa parte de cima, ou seja, no caso de se tudo tiver ok, segundo o usuário, o cadastro será feito, nada acontece.

A sub inteira está abaixo. Alguém consegue me dizer onde estou errado, por gentileza?

Código: Selecionar todos
Sub Novo_Cadastro()

Dim resposta As Integer

'Cadastra novas madrinhas e padrinhos
    
    If Sheets("Cadastrar").Range("B3") = "" Then
        
        MsgBox "Por favor preecha o nome, é um campo obrigatório", vbExclamation, "Cadastro não efetuado"
        Exit Sub
    
    End If
    
    If Sheets("Cadastrar").Range("C3") = "" Then
        
        MsgBox "Por favor preecha a data de nascimento, é um campo obrigatório", vbExclamation, "Cadastro não efetuado"
        Exit Sub
    
    End If

    If Sheets("Cadastrar").Range("D3") = "" Then
        
        MsgBox "Por favor preecha o gênero, é um campo obrigatório", vbExclamation, "Cadastro não efetuado"
        Exit Sub
    
    End If

    If Sheets("Cadastrar").Range("D3") = "" Then
        
        MsgBox "Por favor preecha a data preferida, é um campo obrigatório", vbExclamation, "Cadastro não efetuado"
        Exit Sub
    
    End If

    If Sheets("Cadastrar").Range("G3") = "" Then
        
        MsgBox "Por favor preecha o contato, é um campo obrigatório", vbExclamation, "Cadastro não efetuado"
        Exit Sub
    
    End If

resposta = MsgBox("Você tem certeza que todas as informações estão corretas? Lembre que elas não poderão ser alteradas após o cadastro.", vbYesNo + vbQuestion, "Cuidado!")
    
    If answer = vbYes Then
    
        Sheets("Cadastrar").Range("A3:L3").Copy
        Sheets("Bco_Padrinhos").Select
        Call LinhaVazia
        Selection.PasteSpecial Paste:=xlPasteValues
        Selection.End(xlUp).Select
        Sheets("Cadastrar").Select
        Range("B2:L2").ClearContents
        ActiveWorkbook.RefreshAll
        ActiveWorkbook.Save
        MsgBox "Cadastro realizado com sucesso!", vbInformation, ""
    
    Else
    
        'Não faça nada
        
    End If
       
End Sub
Editado pela última vez por yuricgy em 25 Abr 2021 às 16:51, em um total de 1 vez.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord