pedro_mexico
18-04-2018 11:22:11
bom dia amigos.
tenho um formulario em que introduzo o historico das viaturas da empresa.
o formulario grava os dados em uma panilha inicial , selecionamos uma combobox com a matricula da viatura e ele vai fazer gravar na linha certa da panilha.
mas agora eu queria criar uma panilha de historico para cada matricula e ja coloquei um codigo que envio em baixo,
para fazer gravacao dos dados na panilha inicial e numa panilha com a matricula da viatura, mas para a primeira viatura do codigo, ele faz a gravaçao bem, mas para as outras viaturas ele so grava na panilha inicial.
espero que me consigam dar umas ideias.
obrigado
tenho um formulario em que introduzo o historico das viaturas da empresa.
o formulario grava os dados em uma panilha inicial , selecionamos uma combobox com a matricula da viatura e ele vai fazer gravar na linha certa da panilha.
mas agora eu queria criar uma panilha de historico para cada matricula e ja coloquei um codigo que envio em baixo,
Código: Selecionar todos
Private Sub botao_gravar_Click()
Dim linha As Object
Select Case cboMatricula.Value 'Selecione de acordo o valor de ComboBox
Case Is = "XP-91-52"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1") '.End(xlUp)
If Not TextBox1.Text = vbNullString Then 'codigo para se a textbox estiver vazia nao alterar dados na folha
linha.Offset(1, 1).Value = TextBox1.Text 'grava na (linha, coluna)'0
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(1, 2).Value = TextBox2.Text '1
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(1, 10).Value = TextBox3.Text '9
End If
linha.Offset(1, 17).Value = cmb_pneus '16
If Not TextBox4.Text = vbNullString Then
linha.Offset(1, 18).Value = TextBox4.Text '17
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(1, 19).Value = TextBox5.Text '18
End If
If CheckBox1.Value = True Then
linha.Offset(1, 15).Value = "SIM" '14
'Range("Q4").Interior = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Select Case cboMatricula.Value
Case Is = "XP-91-52"
ThisWorkbook.Sheets("XP-91-52").Select 'Informe entre aspas "" o nome da folha correspondente
End Select
lin = ActiveSheet.UsedRange.Rows.Count + 1 'Define a variavel Lin como a ultima linha e soma + 1
Cells(lin, "B") = TextBox1 'Primeira linha em branco na coluna A = txtapelido
Cells(lin, "C") = TextBox2 'Primeira linha em branco na coluna B = txtnii1
Cells(lin, "D") = TextBox3 'E assim por diante até o último campo do form
Cells(lin, "F") = cmb_pneus
Cells(lin, "G") = TextBox4
Cells(lin, "H") = TextBox5
Cells(lin, "E") = TextBox6
Cells(lin, "I") = TextBox7
Case Is = "12-82-GL"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(2, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(2, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(2, 10).Value = TextBox3.Text
End If
linha.Offset(2, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(2, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(2, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(2, 15).Value = "SIM"
'Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Select Case cboMatricula.Value
Case Is = "12-82-GL"
ThisWorkbook.Sheets("12-82-GL").Select 'Informe entre aspas "" o nome da folha correspondente
End Select
lin = ActiveSheet.UsedRange.Rows.Count + 1 'Define a variavel Lin como a ultima linha e soma + 1
Cells(lin, "B") = TextBox1 'Primeira linha em branco na coluna A = txtapelido
Cells(lin, "C") = TextBox2 'Primeira linha em branco na coluna B = txtnii1
Cells(lin, "D") = TextBox3 'E assim por diante até o último campo do form
Cells(lin, "F") = cmb_pneus
Cells(lin, "G") = TextBox4
Cells(lin, "H") = TextBox5
Cells(lin, "E") = TextBox6
Cells(lin, "I") = TextBox7
Case Is = "18-45-FH"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(3, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(3, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(3, 10).Value = TextBox3.Text
End If
linha.Offset(3, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(3, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(3, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(3, 15).Value = "SIM"
'Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Select Case cboMatricula.Value
Case Is = "18-45-FH"
ThisWorkbook.Sheets("18-45-FH").Select 'Informe entre aspas "" o nome da folha correspondente
End Select
lin = ActiveSheet.UsedRange.Rows.Count + 1 'Define a variavel Lin como a ultima linha e soma + 1
Cells(lin, "B") = TextBox1 'Primeira linha em branco na coluna A = txtapelido
Cells(lin, "C") = TextBox2 'Primeira linha em branco na coluna B = txtnii1
Cells(lin, "D") = TextBox3 'E assim por diante até o último campo do form
Cells(lin, "F") = cmb_pneus
Cells(lin, "G") = TextBox4
Cells(lin, "H") = TextBox5
Cells(lin, "E") = TextBox6
Cells(lin, "I") = TextBox7
Case Is = "57-24-TD"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(4, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(4, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(4, 10).Value = TextBox3.Text
End If
linha.Offset(4, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(4, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(4, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(4, 15).Value = "SIM"
'Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Case Is = "XX-XX-XX"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(5, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(5, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(5, 10).Value = TextBox3.Text
End If
linha.Offset(5, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(5, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(5, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(5, 15).Value = "SIM"
'Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Case Is = "70-EE-12"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(6, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(6, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(6, 10).Value = TextBox3.Text
End If
linha.Offset(6, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(6, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(6, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(6, 15).Value = "SIM"
'Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
Case Is = "52-GH-12"
ThisWorkbook.Sheets("Mapa Viaturas").Select
Set linha = Folha3.Range("C1")
If Not TextBox1.Text = vbNullString Then
linha.Offset(7, 1).Value = TextBox1.Text
End If
If Not TextBox2.Text = vbNullString Then
linha.Offset(7, 2).Value = TextBox2.Text
End If
If Not TextBox3.Text = vbNullString Then
linha.Offset(7, 10).Value = TextBox3.Text
End If
linha.Offset(7, 17).Value = cmb_pneus
If Not TextBox4.Text = vbNullString Then
linha.Offset(7, 18).Value = TextBox4.Text
End If
If Not TextBox5.Text = vbNullString Then
linha.Offset(7, 19).Value = TextBox5.Text
End If
If CheckBox1.Value = True Then
linha.Offset(7, 15).Value = "SIM"
' Range("Q5").Interior.Color = vbWhite
Else
'linha.Offset(3, 14).Value = "NÂO"
End If
End Select
MsgBox ("Gravado com Sucesso")
TextBox1.Value = Empty
TextBox2.Value = Empty
TextBox3.Value = Empty
TextBox4.Value = Empty
TextBox5.Value = Empty
cmb_pneus = Empty
MultiPage1.Value = 0
End Sub
espero que me consigam dar umas ideias.
obrigado