Ir para conteúdo
Fórum Script Brasil

Yago bezerra

Membros
  • Total de itens

    8
  • Registro em

  • Última visita

Posts postados por Yago bezerra

  1. Corrigido! deu certo.

    inseri um exit sub para que  não ocorra o preenchimento de celula vazia.

    Obrigado!. segue código para uso da comunidade

     

    Sub B_cadastrarauditor_Click()

    Dim TXT_auditorname As MSForms.TextBox
    Set TXT_auditorname = Me.TXT_auditorname
    Dim ws As Worksheet
    Dim OB_off As MSForms.OptionButton
    Set OB_off = Me.OB_off
    Dim OB_man As MSForms.OptionButton
    Set OB_man = Me.OB_man
    Dim nextRow As Long
        

        If OB_off = False And OB_man = False Then
            MsgBox "Selecione em qual área será cadastrado o auditor"
            Exit Sub
        ElseIf TXT_auditorname = "" Then
            MsgBox "Preencha o nome do auditor"
            Exit Sub
        End If

        
        If OB_off = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_off").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_off").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
        ElseIf OB_man = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_man").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_man").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
        End If

        Unload reg_auditor
            
    End Sub

  2. Fiz a alteração trocando 

    "reg_auditor.close" para "Unload reg_auditor"

    sobre o exemplo acredito que não tem um exemplo direto pois é um sistema de gerenciamento de 5S que estou tentando criar na empresa, o mais próximo disso seria um formulário de cadastro com userform.

    eu sou novo aqui(até em forums haha), então descupe por esses erros.

    excel não consegui postar, mas vou deixar o código em texto.

     


    Sub B_cadastrarauditor_Click()

    Dim audit_off As Object
    Dim audit_man As Object
    Dim a_man As Object
    Dim a_off As Object
    Dim TXT_auditorname As MSForms.TextBox
    Dim OB_off As MSForms.OptionButton
    Dim OB_man As MSForms.OptionButton
    Dim ws As Worksheet
    Dim nextRow As Long

    If OB_off.Enabled And OB_man.Enabled Then
        With OB_off
        MsgBox "Selecione em qual área será cadastrado o auditor"
        End With
    End If

        
    If TXT_auditorname = "" Then
            MsgBox "Preencha o nome do auditor"

        ElseIf OB_off = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_off").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_off").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
        ElseIf OB_man = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_man").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_man").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
    End If

    Unload reg_auditor

        
    End Subimage.png.7cf0f4c333039b79b22a0c4c72f1e42c.png

  3. Bom dia. 

    Já verifiquei os nomes das teclas do userform com o código porém continuo com esse erro.
    diversas vezes postei no ChatGPT e ele corrigiu mas o erro persiste.

     

    Sub B_cadastrarauditor_Click()

    Dim audit_off As Object
    Dim audit_man As Object
    Dim a_man As Object
    Dim a_off As Object
    Dim TXT_auditorname As MSForms.TextBox
    Set TXT_auditorname = Me.TXT_auditorname
    Dim ws As Worksheet
    Dim OB_off As MSForms.OptionButton
    Set OB_off = Me.OB_off
    Dim OB_man As MSForms.OptionButton
    Set OB_man = Me.OB_man
    Dim nextRow As Long

        If OB_off = False And OB_man = False Then
            MsgBox "Selecione em qual área será cadastrado o auditor"
            Exit Sub
        ElseIf TXT_auditorname = "" Then
            MsgBox "Preencha o nome do auditor"
        End If

        
        If OB_off = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_off").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_off").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
        ElseIf OB_man = True Then
            Set ws = ThisWorkbook.Sheets("Database_tables")
        
            'Get the next empty row in the table
            nextRow = ws.ListObjects("audit_man").Range.Rows.Count + 1
        
            'Capture data from the UserForm text box
            ws.ListObjects("audit_man").ListRows.Add.Range(1, 1).Value = TXT_auditorname.Value
        
            'Clear the UserForm text box after data is captured
            TXT_auditorname.Value = ""
            
            MsgBox "Auditor cadastrado com sucesso"
            
        End If

        reg_auditor.Close
       
        
    End Sub

     

    image.png.7cf0f4c333039b79b22a0c4c72f1e42c.png

×
×
  • Criar Novo...