Notifications
Clear all

Enviar dados para diferentes planilhas

4 Posts
2 Usuários
0 Reactions
1,171 Visualizações
(@julios)
Posts: 15
Eminent Member
Topic starter
 

Estou desenvolvendo um aplicativo para meu chefe que funciona da seguinte forma: quando a planilha é aberta, o usuário clica em um botão que aciona o menu Adicionar Sinistro. Até ai tudo bem, já está tudo funcionando, mas eu encontrei um problema. Após preencher todos os campos, quando clicar no botão Enviar, o aplicativo deve enviar os dados para diferentes planilhas. Cada profissional tem uma planilha e o aplicativo deveria enviar os dados para a planilha referente ao dado inserido no campo Profissional.

Menu Adicionar Sinistro:

Planilhas de profissionais

Exemplo:
O usuário preencheu todos os campos, e no campo Profissional inseriu o dado "Danilo". Ao clicar no botão enviar, o aplicativo vai inserir todos os dados na planilha Danilo.

Código do botão Enviar

Private Sub cmdEnviar_Click()
'Ativar a primeira planilha
ThisWorkbook.Worksheets("Dados Sinistros").Activate
'Selecionar a célula A3
Range("A3").Select

'Procurar a primeira célula vazia
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 = txtSinistro.Value
ActiveCell.Offset(0, 1).Value = cboOperadora.Value
ActiveCell.Offset(0, 2).Value = txtPlaca.Value
ActiveCell.Offset(0, 3).Value = txtLocal.Value
ActiveCell.Offset(0, 5).Value = txtData.Value
ActiveCell.Offset(0, 6).Value = txtValor.Value
ActiveCell.Offset(0, 7).Value = txtObs.Value

'Carregar o sexo do cliente dos botões de opção
If optMecanico.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Mecânico"
End If

If optChaveiro.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Chaveiro"
End If

If optResidencial.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Residencial"
End If

If optReboque.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Reboque"
End If

If optOutro.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Outros"
End If

'Limpar as caixas de texto
txtSinistro.Value = Empty
txtObs.Value = Empty
txtLocal.Value = Empty
txtData.Value = Empty
txtPlaca.Value = Empty
txtValor.Value = Empty
'Limpar as caixas de combinação
cboOperadora.Value = Empty
cboProfissional.Value = Empty

'Limpar os botões OptionButton
optMecanico.Value = False
optChaveiro.Value = False
optResidencial.Value = False
optReboque.Value = False
optOutro.Value = False

'Colocar o foco na primeira caixa de texto
txtSinistro.SetFocus
End Sub

P.S.:
Não tenho muita noção de programação, mas acho que seria mais ou menos o seguinte:

If opt.Mecanico.Value = "x" Then
Do
ThisWorkbook.Worksheets("x").Activate
Range("A3").Select
End If

If opt.Mecanico.Value = "y" Then
Do
ThisWorkbook.Worksheets("y").Activate
Range("A3).Select
End If

Preciso de ajudar urgente! Aguardo retorno. Abraços!

 
Postado : 18/02/2013 7:38 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

JuioS,

Boa Tarde!

Creio que o seu problema seja resolvido com pequena alteração no seu código (supondo, por exemplo, que seu combo onde você escolhe o profissional, se chama Cmb_Profissional, como abaixo:

Private Sub cmdEnviar_Click()
'Ativar a primeira planilha
ThisWorkbook.Worksheets(Cmb_Profissional.Value).Activate
'Selecionar a célula A3
Range("A3").Select

'Procurar a primeira célula vazia
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 = txtSinistro.Value
ActiveCell.Offset(0, 1).Value = cboOperadora.Value
ActiveCell.Offset(0, 2).Value = txtPlaca.Value
ActiveCell.Offset(0, 3).Value = txtLocal.Value
ActiveCell.Offset(0, 5).Value = txtData.Value
ActiveCell.Offset(0, 6).Value = txtValor.Value
ActiveCell.Offset(0, 7).Value = txtObs.Value

'Carregar o sexo do cliente dos botões de opção
If optMecanico.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Mecânico"
End If

If optChaveiro.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Chaveiro"
End If

If optResidencial.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Residencial"
End If

If optReboque.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Reboque"
End If

If optOutro.Value = True Then
    ActiveCell.Offset(0, 4).Value = "Outros"
End If

'Limpar as caixas de texto
txtSinistro.Value = Empty
txtObs.Value = Empty
txtLocal.Value = Empty
txtData.Value = Empty
txtPlaca.Value = Empty
txtValor.Value = Empty
'Limpar as caixas de combinação
cboOperadora.Value = Empty
cboProfissional.Value = Empty

'Limpar os botões OptionButton
optMecanico.Value = False
optChaveiro.Value = False
optResidencial.Value = False
optReboque.Value = False
optOutro.Value = False

'Colocar o foco na primeira caixa de texto
txtSinistro.SetFocus
End Sub
 
Postado : 19/02/2013 12:03 pm
(@julios)
Posts: 15
Eminent Member
Topic starter
 

Milhões de agradecimentos, Wagner!!! Você salvou o meu mês. Problema resolvido.

 
Postado : 19/02/2013 12:47 pm
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

Valeu JulioS,

Obrigado.

 
Postado : 19/02/2013 6:01 pm