Notifications
Clear all

Inserir dados a partir do Formulario

13 Posts
3 Usuários
0 Reactions
2,761 Visualizações
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Bom dia!

Tenho uma planinha onde
Plan1 = TI
Plan2 = Chamado TI
Plan3 = Integração

Na "TI" tem um botão para abrir o formulário do VBA, após aberto digito as informações que deverão ser inseridas no "Chamado TI" ou "Integração" , porém não consigo fazer isso,

a unica forma que consegui, foi criando 2 option button Chamado T.I e Integração com o comando Sheets("chamadoTI").select para selecionar a planilha... ai sim o dados são inseridos na planilha....porém gostaria que não tivesse que ir para a planilha para ele inserir o dado.

A pergunta é como inserir os dados do formulario em uma planilha que não é a ativa no momento, no caso na Chamado TI ou Integração.

Att

Thales

 
Postado : 06/09/2012 7:15 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Uma forma seria

with sheets("ChamadoTI")
.cells(x,y)=....
ou
.Range("A" & lin)....
end with

ou
sheets('ChamadoTI").cells(x,y)=....
sheets('ChamadoTI").Range("A" 7 lin)=....

 
Postado : 06/09/2012 7:31 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Estava pensando em fazer algo com o Select Case, mas nao sei usar muito bem, tipo... seria assim:
Case 1
optbuttonChamadoTI = True
sheets("chamadoTI").cells(x,y)
'carrega os dados digitados no form.
???.Value = txtNome.Value
???.Value = ComboBox1.Value
???.Value = TextBox1.Value
???.Value = txtDescrição.Value
Case 2
optbuttonChamadoTI = True
sheets("chamadoTI").cells(x,y)
'carrega os dados digitados no form.
???.Value = txtNome.Value
???.Value = ComboBox1.Value
???.Value = TextBox1.Value
???.Value = txtDescrição.Value
end select

Acho que ta tudo errado....o "???" não sei o que colocar...

Reinaldo vc fez curso de excel???? Tem pela internet?

Esses são meus comandos no VBA:

Private Sub cmdOk_Click()

If txtNome.Text = "" Then
MsgBox "Digite o Nome de usuario"
txtNome.SetFocus
Exit Sub
End If

'Procurar a primeira célula vazia
Do
If Not (IsEmpty(ActiveCell)) Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True

Range("B2").Select
Do
If Not (IsEmpty(ActiveCell)) Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True

'Carregar os dados digitados nas caixas de texto para a planilha
ActiveCell.Value = txtNome.Value
ActiveCell.Offset(0, 0).Value = txtNome.Value
ActiveCell.Offset(0, 1).Value = ComboBox1.Value
ActiveCell.Offset(0, 2).Value = TextBox1.Value
ActiveCell.Offset(0, 3).Value = txtDescrição.Value
'Inserir data e hora
ActiveCell.Offset(0, 4).Value = Now

Dim Response
Sheets(1).Select
Response = MsgBox("Deseja inserir novo chamado?", vbYesNo, "Atenção")
Select Case Response
Case 6
txtNome.Value = Empty
txtDescrição.Value = Empty
TextBox1.Value = Empty
txtNumeroChamado = Empty
'Limpar as caixas de combinação
ComboBox1.Value = Empty
'Limpar os botões CheckBox e OptionButton
optChamadoTI.Value = False
optIntegração.Value = False
'Limpar as caixas de texto
Sheets("TI").Select
Case 7
ActiveWorkbook.Close savechanges:=True
End Select

End Sub
Private Sub ComboBox1_Change()
TextBox1.Value = Cells(ComboBox1.ListIndex + 4, 19).Value
End Sub
Private Sub Image1_Click()
MsgBox "Quando for Chamado T.I, e não se relacionar a uma empresa, favor colocar Empresa 0000 - Nenhum.", vbOKOnly, "Ajuda"
End Sub
Private Sub cmdCancelar_Click()
'quando o botão cancelar for pressionado, o formulario deverá ser descarregado.
'Limpar as caixas de texto
txtNome.Text = Empty
txtDescrição.Text = Empty
TextBox1.Text = Empty
txtNumeroChamado.Text = Empty
'Limpar as caixas de combinação
'Colocar o foco na primeira caixa de texto
txtNome.SetFocus
End Sub
Private Sub optChamadoTI_Change()
Sheets("CHAMADOS TI").Visible = True
Sheets("CHAMADOS TI").Select

End Sub
Private Sub optIntegração_Change()
Sheets("INTEGRAÇÃO").Visible = True
Sheets("INTEGRAÇÃO").Select

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Hauahuahua, Não vai conseguir sair!!" _
, vbCritical _
, "Erro"
End If
End Sub
Private Sub cmbSair_Click()
Sheets("TI").Select
Unload Me
End Sub

 
Postado : 06/09/2012 8:37 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Veja se assim o btn cmbOk atende:
(Obs.: os demais dados nessa rotina creio que não se aplicam, se julgar que sim me fale o objetivo)

Private Sub cmdOk_Click()
Dim lastRow As Long, Response
If txtNome.Text = "" Then
MsgBox "Digite o Nome de usuario"
txtNome.SetFocus
Exit Sub
End If

'Carregar os dados digitados nas caixas de texto para a planilha
If optbuttonChamadoTI = True Then
'optbuttonChamadoTI = True
    With Sheets("chamadoTI")
    'DEtermina qual a ultima celula preenchida na coluna A
    lastRow = .Cells(Cells.Rows.Count, "A").End(xlUp).Row
    
    'carrega os dados digitados no form.
        .Cells(lastRow + 1, 2) = txtNome.Value
        .Cells(lastRow + 1, 3) = ComboBox1.Value
        .Cells(lastRow + 1, 4) = TextBox1.Value
        .Cells(lastRow + 1, 5) = txtDescrição.Value
        .Cells(lastRow + 1, 6) = Format(Date, "DD/MM/YYYY")

Else
    With Sheets("Integração")
    'DEtermina qual a ultima celula preenchida na coluna A
    lastRow = .Cells(Cells.Rows.Count, "A").End(xlUp).Row
    
    'carrega os dados digitados no form.
        .Cells(lastRow + 1, 2) = txtNome.Value
        .Cells(lastRow + 1, 3) = ComboBox1.Value
        .Cells(lastRow + 1, 4) = TextBox1.Value
        .Cells(lastRow + 1, 5) = txtDescrição.Value
        .Cells(lastRow + 1, 6) = Format(Date, "DD/MM/YYYY")
End If

End Sub
 
Postado : 06/09/2012 10:06 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Bom dia!

Deu certo o que eu precisava, porém de erro deu bloco IF sem END IF - ai coloquei "end with" deu certo, porém ele está inserindo as informações somente na planilha ("integração")

Att

 
Postado : 10/09/2012 5:21 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Creio que faltavam 2 end with, veja se funciona, caso contrario disponhas seu exemplo.

    Private Sub cmdOk_Click()
    Dim lastRow As Long, Response
    If txtNome.Text = "" Then
    MsgBox "Digite o Nome de usuario"
    txtNome.SetFocus
    Exit Sub
    End If

    'Carregar os dados digitados nas caixas de texto para a planilha
    If optbuttonChamadoTI = True Then
    'optbuttonChamadoTI = True
        With Sheets("chamadoTI")
        'DEtermina qual a ultima celula preenchida na coluna A
        lastRow = .Cells(Cells.Rows.Count, "A").End(xlUp).Row
       
        'carrega os dados digitados no form.
            .Cells(lastRow + 1, 2) = txtNome.Value
            .Cells(lastRow + 1, 3) = ComboBox1.Value
            .Cells(lastRow + 1, 4) = TextBox1.Value
            .Cells(lastRow + 1, 5) = txtDescrição.Value
            .Cells(lastRow + 1, 6) = Format(Date, "DD/MM/YYYY")
         end with
    Else
        With Sheets("Integração")
        'DEtermina qual a ultima celula preenchida na coluna A
        lastRow = .Cells(Cells.Rows.Count, "A").End(xlUp).Row
       
        'carrega os dados digitados no form.
            .Cells(lastRow + 1, 2) = txtNome.Value
            .Cells(lastRow + 1, 3) = ComboBox1.Value
            .Cells(lastRow + 1, 4) = TextBox1.Value
            .Cells(lastRow + 1, 5) = txtDescrição.Value
            .Cells(lastRow + 1, 6) = Format(Date, "DD/MM/YYYY")
       end with
 End If

    End Sub
 
Postado : 10/09/2012 5:25 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

deu certo... descobri que o comando estava errando... optbuttonChamadoTI... mas é optChamadoTI o correto.

Att

 
Postado : 10/09/2012 6:19 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Deu certo, agora estou tentando fazer o mesmo para o cmdPesquisar...rsrsrsr

Como faço para ele procurar o código nas duas Planilhas?
Eu consigo da mesma forma que o cmdOK, ativando a planilha na qual desejo pesquisar.

Att

 
Postado : 10/09/2012 6:24 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Bom dia!

Segue planilha anexada, para que possa me ajudar, consegui fazer com que a consulta pesquise sem ter que ir na sheet para puxar as informações, porém não estou conseguindo dar baixa, quando clico em "Processar" que deveria inserir na planilhas nas duas ultimas colunas seguindo a linha do numero chamado pesquisado.

Att

 
Postado : 12/09/2012 5:50 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Veja se lheauxilia

 
Postado : 12/09/2012 10:19 am
(@skadis)
Posts: 18
Eminent Member
Topic starter
 

Parabéns mesmo...

O que precisava mesmo.

Att

 
Postado : 12/09/2012 12:17 pm
(@soudaki)
Posts: 0
New Member
 

Boa tarde pessoal!!!

Estou com um problema na minha planilha, eu fiz o useform e coloquei os dados que preciso. Eu montei o código mas quando mando cadastrar, da erro de execução 424.

Private Sub cmdCadastrar_Click()
'Ativar a primeira planilha
ThisWorkbook.Worksheets("Banco de Dados").Activate
Rows("4:4").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

'Carregar os dados digitados nas caixas de texto para a planilha
ActiveCell.Value = txtCódigo.Value ----------------------------------------------------------> aqui que para, não esta copiando os dados da useform para a planilha
ActiveCell.Offset(0, 1).Value = txtNome.Value
ActiveCell.Offset(0, 2).Value = txtEndereco.Value
ActiveCell.Offset(0, 3).Value = txtNúmero.Value
ActiveCell.Offset(0, 4).Value = txtComplemento.Value
ActiveCell.Offset(0, 5).Value = txtBairro.Value
ActiveCell.Offset(0, 6).Value = cboCidade.Value
ActiveCell.Offset(0, 7).Value = txtCEP.Value
ActiveCell.Offset(0, 8).Value = cboCidade.Value
ActiveCell.Offset(0, 9).Value = txtDDD.Value
ActiveCell.Offset(0, 10).Value = txtTelefone.Value
ActiveCell.Offset(0, 11).Value = txtContato.Value
ActiveCell.Offset(0, 12).Value = txtObservações.Value

Minha planilha é para cadastro de clientes, quero que ao clicar em cadastrar, ela insira uma nova linha e depois copie os dados da useform para os campos da planilha "Banco de Dados".
Alguém pode me ajudar???

 
Postado : 05/04/2016 1:30 pm
(@soudaki)
Posts: 0
New Member
 

Quando chega em ActiveCell.Value = txtCódigo.Value, eu clico para ver e aparece txtCódigo = Vazio, não estou conseguindo resolver...

 
Postado : 05/04/2016 1:31 pm