Duas planilhas preenchidas por um unico formulario

FabioPrade

15-02-2012 16:14:03

Amigos, estou montando este projeto e preciso mais uma vez de ajuda.

Criei um formulario que alimenta uma planilha(banco de dados) mas gostaria que este mesmo formulario preenchesse tambem algumas colunas de uma outra planilha do mesmo projeto, planilha (A Prazo), isto e possivel??? Detalhe, na segunda planilha o numero de colunas a preencher e menor.

FabioPrade

16-02-2012 00:10:17

Amigos, consegui a resposta e vou postala aqui para futuros iniciantes como eu, um grande abraço a todos.


Private Sub CommandButton1_Click()
Dim lastRow As Long
'Ativar a primeira planilha
ThisWorkbook.Worksheets("banco de dados").Activate

' Verifica qual a ultima linha preenchida
lastRow = Cells(Rows.Count, 1).End(xlUp).Row

Cells(lastRow + 1, 1) = TextBox1.Text
Cells(lastRow + 1, 2) = TextBox2.Text
Cells(lastRow + 1, 3) = ComboBox1.Text
Cells(lastRow + 1, 4) = ComboBox11.Text
Cells(lastRow + 1, 5) = ComboBox2.Text
Cells(lastRow + 1, 6) = TextBox3.Text
Cells(lastRow + 1, 7) = TextBox4.Text
Cells(lastRow + 1, 8) = TextBox11.Text
Cells(lastRow + 1, 9) = TextBox10.Text
Cells(lastRow + 1, 10) = ComboBox4.Text
Cells(lastRow + 1, 11) = TextBox6.Text
Cells(lastRow + 1, 12) = ComboBox5.Text
Cells(lastRow + 1, 13) = TextBox7.Text
Cells(lastRow + 1, 14) = ComboBox6.Text
Cells(lastRow + 1, 15) = TextBox9.Text
Cells(lastRow + 1, 16) = ComboBox7.Text
Cells(lastRow + 1, 17) = ComboBox3.Text
Cells(lastRow + 1, 18) = TextBox8.Text

'Ativar a Segunda planilha
ThisWorkbook.Worksheets("A Prazo").Activate

' Verifica qual a ultima linha preenchida
lastRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
' Aqui vão os dados(campos) a serem alocados em aprazo
Cells(lastRow, 1) = TextBox1.Text
Cells(lastRow, 2) = TextBox2.Text
Cells(lastRow, 3) = ComboBox1.Text
Cells(lastRow, 4) = ComboBox11.Text
'.....e outros que necessarios

MsgBox "O registro " & Me.ComboBox2 & " foi adicionado com sucesso!!!", 64, "Serviços Diarios"
'Limpar as caixa de texto
TextBox1.Value = Empty
TextBox2.Value = Empty
TextBox3.Value = Empty
TextBox4.Value = Empty
TextBox6.Value = Empty
TextBox7.Value = Empty
TextBox8.Value = Empty
TextBox9.Value = Empty
TextBox10.Value = Empty
TextBox11.Value = Empty
ComboBox1.Value = Empty
ComboBox2.Value = Empty
ComboBox3.Value = Empty
ComboBox4.Value = Empty
ComboBox5.Value = Empty
ComboBox6.Value = Empty
ComboBox7.Value = Empty
ComboBox11.Value = Empty

'Colocar o foco na primeira caixa de texto
formserviçosdiarios.Hide

Sheets("menu").Activate

End Sub

Obs. Meu erro foi colocar dentro desta mesma rotina a ativaçao da segunda planilha depois do comando Empty, ai tornava celulas em branco.