Ir ao conteúdo
  • Cadastre-se

VBA para inserção de muitas linhas de dados em Planilha


Posts recomendados

Prezados,

Estou desenvolvendo um programinha usando o VBA via excel para solicitação de pedido. Ocorre que no momento de transportar as informações só vai 1 linha e preciso que, de uma mesma coluna, sejam transportadas 14, já que por ser um formulário de solicitação de pedido, existem 14 campos para inclusão de materiais. Alguém poderia me ajudar disponibilizando um código que fizesse isso?

OBS: Tenho que o incluir 5 colunas dessa forma. Usei o seguinte código, mas não funciona:

U_L = Plan1.Range("B" & Rows.Count).End(xlUp).Row + 1

If Len(Me.txtQuant) = 0 Then

MsgBox "VOCÊ NÃO DIGITOU NENHUMA QUANTIDADE", vbCritical, "SALVAR"

Exit Sub

Else

Plan1.Cells(U_L, 1) = UCase(Me.TXT_NUMERO)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox1)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec1)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo1)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant1)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox2)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec2)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo2)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant2)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox3)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec3)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo3)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant3)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox4)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec4)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo4)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant4)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox5)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec5)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo5)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant5)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox6)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec6)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo6)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant6)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox7)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec7)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo7)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant7)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox8)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec8)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo8)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant8)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox9)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec9)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo9)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant9)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox10)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec10)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo10)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant10)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox11)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec11)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo11)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant11)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox12)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec12)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo12)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant12)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox13)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec13)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo13)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant13)

Plan1.Cells(U_L, 2) = UCase(Me.ComboBox14)

Plan1.Cells(U_L, 3) = UCase(Me.TextEspec14)

Plan1.Cells(U_L, 4) = UCase(Me.TextInsumo14)

Plan1.Cells(U_L, 5) = UCase(Me.TextQuant14)

MsgBox "SOLICITAÇÃO ARQUIVADA COM SUCESSO"

End If

Obrigada,

Link para o comentário
Compartilhar em outros sites

Tentei mas os dados não estão sendo enviados para a planilha controle que deveria manter o histórico de cadastro do formulário. Rearrumei e ficou conforme abaixo. Você consegue me ajudar a transferir esses dados?? Não está dando erro agora, mas tb não transfere!! Como sou nova nesse negócio de VBA estou tendo dificuldades....

Private Sub btnSALVAR_Click()

Dim iLin As Long

Dim ws As Worksheet

Set ws = Worksheets("CONTROLE")

iLin = 1

'Descobre qual é a primera linha em branco, a partir da linha do cabeçalho (nº 1) e _

da coluna B onde você diz que começam os dados. IMPORTANTE: A coluna B não poderá ter _

células em branco, pois o código para ao encontrar uma célula em branco.

Do While Range("B" & iLin).Value <> ""

iLin = iLin + 1

Loop

'Cadastra as informações

Dim iRow_1 As Long

Dim ws_1 As Worksheet

Set ws_1 = Worksheets.Application.Sheets("CONTROLE")

iRow_1 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_1.Cells(iRow_1, 1).Value = TXT_NUMERO.Value

ws_1.Cells(iRow_1, 2).Value = ComboBox1.Value

ws_1.Cells(iRow_1, 3).Value = TextEspec1.Value

ws_1.Cells(iRow_1, 4).Value = TextInsumo1.Value

ws_1.Cells(iRow_1, 5).Value = TextQuant1.Value

Dim iRow_2 As Long

Dim ws_2 As Worksheet

Set ws_2 = Worksheets.Application.Sheets("CONTROLE")

iRow_2 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_2.Cells(iRow_2, 1).Value = TXT_NUMERO.Value

ws_2.Cells(iRow_2, 2).Value = ComboBox2.Value

ws_2.Cells(iRow_2, 3).Value = TextEspec2.Value

ws_2.Cells(iRow_2, 4).Value = TextInsumo2.Value

ws_2.Cells(iRow_2, 5).Value = TextQuant2.Value

Dim iRow_3 As Long

Dim ws_3 As Worksheet

Set ws_3 = Worksheets.Application.Sheets("CONTROLE")

iRow_3 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_3.Cells(iRow_3, 1).Value = TXT_NUMERO.Value

ws_3.Cells(iRow_3, 2).Value = ComboBox3.Value

ws_3.Cells(iRow_3, 3).Value = TextEspec3.Value

ws_3.Cells(iRow_3, 4).Value = TextInsumo3.Value

ws_3.Cells(iRow_3, 5).Value = TextQuant3.Value

Dim iRow_4 As Long

Dim ws_4 As Worksheet

Set ws_4 = Worksheets.Application.Sheets("CONTROLE")

iRow_4 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_4.Cells(iRow_4, 1).Value = TXT_NUMERO.Value

ws_4.Cells(iRow_4, 2).Value = ComboBox4.Value

ws_4.Cells(iRow_4, 3).Value = TextEspec4.Value

ws_4.Cells(iRow_4, 4).Value = TextInsumo4.Value

ws_4.Cells(iRow_4, 5).Value = TextQuant4.Value

Dim iRow_5 As Long

Dim ws_5 As Worksheet

Set ws_5 = Worksheets.Application.Sheets("CONTROLE")

iRow_5 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_5.Cells(iRow_5, 1).Value = TXT_NUMERO.Value

ws_5.Cells(iRow_5, 2).Value = ComboBox5.Value

ws_5.Cells(iRow_5, 3).Value = TextEspec5.Value

ws_5.Cells(iRow_5, 4).Value = TextInsumo5.Value

ws_5.Cells(iRow_5, 5).Value = TextQuant5.Value

Dim iRow_6 As Long

Dim ws_6 As Worksheet

Set ws_6 = Worksheets.Application.Sheets("CONTROLE")

iRow_6 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_6.Cells(iRow_6, 1).Value = TXT_NUMERO.Value

ws_6.Cells(iRow_6, 2).Value = ComboBox6.Value

ws_6.Cells(iRow_6, 3).Value = TextEspec6.Value

ws_6.Cells(iRow_6, 4).Value = TextInsumo6.Value

ws_6.Cells(iRow_6, 5).Value = TextQuant6.Value

Dim iRow_7 As Long

Dim ws_7 As Worksheet

Set ws_7 = Worksheets.Application.Sheets("CONTROLE")

iRow_7 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_7.Cells(iRow_7, 1).Value = TXT_NUMERO.Value

ws_7.Cells(iRow_7, 2).Value = ComboBox7.Value

ws_7.Cells(iRow_7, 3).Value = TextEspec7.Value

ws_7.Cells(iRow_7, 4).Value = TextInsumo7.Value

ws_7.Cells(iRow_7, 5).Value = TextQuant7.Value

Dim iRow_8 As Long

Dim ws_8 As Worksheet

Set ws_8 = Worksheets.Application.Sheets("CONTROLE")

iRow_8 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_8.Cells(iRow_8, 1).Value = TXT_NUMERO.Value

ws_8.Cells(iRow_8, 2).Value = ComboBox8.Value

ws_8.Cells(iRow_8, 3).Value = TextEspec8.Value

ws_8.Cells(iRow_8, 4).Value = TextInsumo8.Value

ws_8.Cells(iRow_8, 5).Value = TextQuant8.Value

Dim iRow_9 As Long

Dim ws_9 As Worksheet

Set ws_9 = Worksheets.Application.Sheets("CONTROLE")

iRow_9 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_9.Cells(iRow_9, 1).Value = TXT_NUMERO.Value

ws_9.Cells(iRow_9, 2).Value = ComboBox9.Value

ws_9.Cells(iRow_9, 3).Value = TextEspec9.Value

ws_9.Cells(iRow_9, 4).Value = TextInsumo9.Value

ws_9.Cells(iRow_9, 5).Value = TextQuant9.Value

Dim iRow_10 As Long

Dim ws_10 As Worksheet

Set ws_10 = Worksheets.Application.Sheets("CONTROLE")

iRow_10 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_10.Cells(iRow_10, 1).Value = TXT_NUMERO.Value

ws_10.Cells(iRow_10, 2).Value = ComboBox10.Value

ws_10.Cells(iRow_10, 3).Value = TextEspec10.Value

ws_10.Cells(iRow_10, 4).Value = TextInsumo10.Value

ws_10.Cells(iRow_10, 5).Value = TextQuant10.Value

Dim iRow_11 As Long

Dim ws_11 As Worksheet

Set ws_11 = Worksheets.Application.Sheets("CONTROLE")

iRow_11 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_11.Cells(iRow_11, 1).Value = TXT_NUMERO.Value

ws_11.Cells(iRow_11, 2).Value = ComboBox11.Value

ws_11.Cells(iRow_11, 3).Value = TextEspec11.Value

ws_11.Cells(iRow_11, 4).Value = TextInsumo11.Value

ws_11.Cells(iRow_11, 5).Value = TextQuant11.Value

Dim iRow_12 As Long

Dim ws_12 As Worksheet

Set ws_12 = Worksheets.Application.Sheets("CONTROLE")

iRow_12 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_12.Cells(iRow_12, 1).Value = TXT_NUMERO.Value

ws_12.Cells(iRow_12, 2).Value = ComboBox12.Value

ws_12.Cells(iRow_12, 3).Value = TextEspec12.Value

ws_12.Cells(iRow_12, 4).Value = TextInsumo12.Value

ws_12.Cells(iRow_12, 5).Value = TextQuant12.Value

Dim iRow_13 As Long

Dim ws_13 As Worksheet

Set ws_13 = Worksheets.Application.Sheets("CONTROLE")

iRow_13 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_13.Cells(iRow_13, 1).Value = TXT_NUMERO.Value

ws_13.Cells(iRow_13, 2).Value = ComboBox13.Value

ws_13.Cells(iRow_13, 3).Value = TextEspec13.Value

ws_13.Cells(iRow_13, 4).Value = TextInsumo13.Value

ws_13.Cells(iRow_13, 5).Value = TextQuant13.Value

Dim iRow_14 As Long

Dim ws_14 As Worksheet

Set ws_14 = Worksheets.Application.Sheets("CONTROLE")

iRow_14 = ws_1.Cells(Rows.Count, 2) _

.End(xlUp).Offset(1, 0).Row

ws_14.Cells(iRow_14, 1).Value = TXT_NUMERO.Value

ws_14.Cells(iRow_14, 2).Value = ComboBox14.Value

ws_14.Cells(iRow_14, 3).Value = TextEspec14.Value

ws_14.Cells(iRow_14, 4).Value = TextInsumo14.Value

ws_14.Cells(iRow_14, 5).Value = TextQuant14.Value

MsgBox "DADOS GRAVADOS COM SUCESSO!"

Muito Obrigada!

Link para o comentário
Compartilhar em outros sites

  • 2 anos depois...

Boa tarde a todos,

 

Estou um dúvida bem parecida, tenho uma planilha que uso o vba para inserir dados nela e deixei 40 linhas para digitação de pedido, após isso tem o total do pedido, quero fazer com que após a ultima linha dessa area do pedido, seja acrescentado uma nova linha e copiando as formulas da linha anterior.

 

Alguem pode me auxiliar?

 

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!