Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por fabiolopes
#61254
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
#61262
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!
fabiolopes agradeceu por isso
Por osvaldomp
#61268
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
fabiolopes agradeceu por isso
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord