Qual o erro eq soluçao

Anônima
2025-01-15T12:00:08+00:00

Boas Tardes

Tenho um codigo em vba que necessito que ele deixe 3 caixas do formulario com os dados anteriores, deixo aqui ate onde consegui chegar:

Private Sub btnExportar_ClicK()

Sheets("Com").Select
Linha = Range("B100000").End(xlUp).Row + 1
Cells(Linha, 2) = DateValue(txtdata.Value)
Cells(Linha, 3) = txtpecas.Value
Cells(Linha, 4) = txtdescricao.Value
Cells(Linha, 5) = txtrefcliente.Value
Cells(Linha, 6) = TextBox1.Value
Cells(Linha, 12) = ComboBox1.Value
Cells(Linha, 11) = Fatura.Value
Cells(Linha, 10) = txtqtde.Value
Cells(Linha, 7) = txtnoks.Value
Cells(Linha, 8) = hinicio.Value
Cells(Linha, 9) = hfim.Value

MsgBox "Registro Inserido", 6, "Inserir"
resposta = MsgBox("Novo Registro?", 36, "Inserir")

If resposta = vbYes Then

'txtdata = ""
txtpecas = ""
txtdescricao = ""
txtrefcliente = ""
TextBox1 = ""
'ComboBox1 = ""
'Fatura = ""
txtqtde = ""
txtnoks = ""
hinicio = ""
hfim = ""
txtdescricao = ""
txtrefcliente = ""

txtdata.SetFocus

End If
If resposta = vbNo Then

'txtdata = ""
txtpecas = ""
txtdescricao = ""
txtrefcliente = ""
TextBox1 = ""
'ComboBox1 = ""
'Fatura = ""
txtqtde = ""
txtnoks = ""
hinicio = ""
hfim = ""
txtdescricao = ""
txtrefcliente = ""
txtobs = ""
TxtPausas = ""

Else
Dim objeto As Control

For Each objeto In Me.Controls
If TypeName(objeto) = "TextBox" Or TypeName(objeto) = "ComboBox" Then
            objeto.Text = ""
            End If
Next objeto

End If
End Sub

Pretendo que o txtdat, Combobox1 e Fatura fiquem com os valores ja introduzidos. Porque esta a limpar tudo.

Obrigado pela ajuda

Microsoft 365 e Office | Excel | Para empresas | Windows

Pergunta bloqueada. Essa pergunta foi migrada da Comunidade de Suporte da Microsoft. É possível votar se é útil, mas não é possível adicionar comentários ou respostas ou seguir a pergunta.

0 comentários Sem comentários
Resposta aceita pelo autor da pergunta
Anônima
2025-01-15T14:36:27+00:00

Esta resposta foi traduzida automaticamente. Como resultado, pode haver erros gramaticais ou palavras estranhas.

Olá AdrianoPaulo,

Para manter os valores inseridos, incorpore um Selecionar... Declaração do caso.

Espero que isso ajude:

Private Sub btnExportar_ClicK()
    Sheets("Com").Select
    
    Linha = Range("B100000").End(xlUp).Row + 1
    
    Cells(Linha, 2) = DateValue(txtdata.Value) ' 1
    Cells(Linha, 3) = txtpecas.Value
    Cells(Linha, 4) = txtdescricao.Value
    Cells(Linha, 5) = txtrefcliente.Value
    Cells(Linha, 6) = TextBox1.Value
    Cells(Linha, 12) = ComboBox1.Value ' 2
    Cells(Linha, 11) = Fatura.Value
    Cells(Linha, 10) = txtqtde.Value
    Cells(Linha, 7) = txtnoks.Value
    Cells(Linha, 8) = hinicio.Value
    Cells(Linha, 9) = hfim.Value
    
    MsgBox "Registro Inserido", 6, "Inserir"
    resposta = MsgBox("Novo Registro?", 36, "Inserir")
    
    If resposta = vbYes Then
        Dim objeto As Control
        
        For Each objeto In Me.Controls
            If TypeName(objeto) = "TextBox" Or TypeName(objeto) = "ComboBox" Then
                Select Case objeto.Name
                    ' /* Keep the values you have entered. */
                    Case "txtdata", "ComboBox1", "Fatura"
                        ' Do nothing here.
                    Case Else
                        objeto.Text = ""
                End Select
            End If
        Next
    End If
End Sub

Esta resposta foi útil?

1 pessoa achou esta resposta útil.
0 comentários Sem comentários

2 respostas adicionais

Classificar por: Mais útil
  1. Excluído

    Essa resposta foi excluída devido a uma violação de nosso Código de Conduta. A resposta foi denunciada manualmente ou identificada por meio da detecção automatizada antes da ação ser tomada. Consulte nosso Código de conduta para obter mais informações.


    Os comentários foram desabilitados. Saiba mais

  2. Anônima
    2025-01-15T18:06:47+00:00

    thanks

    Esta resposta foi útil?

    0 comentários Sem comentários