Página 1 de 1

VBA excel preenchimento planilha

Enviado: 29 Dez 2020 às 16:42
por fabiolopes
Boa tarde, tenho a seguinte planilha e está a funcionar bem, no entanto como já vou a preencher 797 demora cerca de 5 seg a percorrer as células todas até chegar a ultima. Não existe maneira de acelerar este processo.
Agradeço pela ajuda. :)

O código é
Private Sub CommandButton1_Click()

Sheets("Faturas").Activate

Range("b3").Select

Do

If ActiveCell.Value <> Empty Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until ActiveCell.Value = Empty



ActiveCell.Value = DateValue(TextBox1.Value)
ActiveCell.Offset(0, 1).Value = TextBox2.Text
ActiveCell.Offset(0, 2).Value = ComboBox1.Text
ActiveCell.Offset(0, 4).Value = TextBox3.Text
ActiveCell.Offset(0, 12).Value = Date
ActiveCell.Offset(0, 16).Value = ComboBox2.Text
ActiveCell.Offset(0, 6).Value = TextBox4.Text

MsgBox ("Inserido com sucesso")


ComboBox1.Text = Empty
TextBox3.Text = Empty
TextBox4.Text = Empty
ActiveWorkbook.Save

ComboBox1.SetFocus

Imagem

Re: VBA excel preenchimento planilha

Enviado: 30 Dez 2020 às 09:19
por wesleyribeiro123
Amigo
Bom dia,

Se tua planilha tiver muitas formulas e cálculos ele vai fazer com que a cada alteração toda a planilha seja recalculada o que eventualmente pode fazer com que a execução de tua macro também demore pra finalizar.

Te aconselho a desativar o cálculo automático no inicio da rotina e reativar no final (via código é claro).
Você pode fazer isso da seguinte forma:
Código: Selecionar todos
Private Sub CommandButton1_Click()
Application.Calculation = xlCalculationManual

    'Inserir teu código aqui

Application.Calculation = xlCalculationAutomatic
End Sub
Espero ter lhe auxiliado!

Re: VBA excel preenchimento planilha

Enviado: 30 Dez 2020 às 12:07
por osvaldomp
Experimente:
Código: Selecionar todos
Private Sub CommandButton1_Click()
 Dim LR As Long
  LR = IIf([B3] = "", 3, [B2].End(4).Row + 1)
  Cells(LR, 2) = DateValue(TextBox1.Value)
  Cells(LR, 3) = TextBox2.Text
  Cells(LR, 4) = ComboBox1.Text
  Cells(LR, 6) = TextBox3.Text
  Cells(LR, 8) = TextBox4.Text
  Cells(LR, 14).Value = Date
  Cells(LR, 18).Value = ComboBox2.Text
  ComboBox1.Text = Empty
  TextBox3.Text = Empty
  TextBox4.Text = Empty
  ActiveWorkbook.Save
  ComboBox1.SetFocus
End Sub

Re: VBA excel preenchimento planilha

Enviado: 04 Jan 2021 às 07:54
por fabiolopes
Muito obrigado pela ajuda!!
Consegui resolver ficou muito melhor!!