Vídeo recomendado
https://youtu.be/diWPPPhW-9E

erro: Estouro no laço For

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
Baldocchi
Colaborador
Colaborador
Mensagens: 15
Registrado em: Qua Ago 09, 2017 8:38 am

erro: Estouro no laço For

Mensagem por Baldocchi »

No código abaixo, qualquer valor que eu coloque superior a 5000 dá erro ESTOURO (apenas isso na mensagem).
Minha planilha base tem mais de 40.000 registros e eu preciso copiar todos esses dados para outra planilha.

Por favor, alguém pode me ajudar?


For I = 1 To 10000 - é aqui que dá erro.
Sheets("ImportBASICO").Select
Range("A" & n).Select
EncontraString = ActiveCell.Value
If Trim(EncontraString) <> "" Then
With Sheets("RESULTADO").Range("D:D")
Set Intervalo = .Find(What:=EncontraString, _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
If Not Intervalo Is Nothing Then
Application.Goto Intervalo, True
'COPIA OS DADOS DA PLANILHA IMPORTACAO PARA A PLANILHA BASICO

'NÚMERO DE ALUNOS
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 9).Value = Sheets("ImportBASICO").Range("C" & n).Value
' 'BANCO
' Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 1).Value = Sheets("ImportBASICO").Range("C" & n).Value
' 'AGÊNCIA
' Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 1).Value = Sheets("ImportBASICO").Range("C" & n).Value
' 'CONTA
' Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 1).Value = Sheets("ImportBASICO").Range("C" & n).Value
'VALOR ESTIMADO: TOTAL
n = n - 15
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 17).Value = Sheets("ImportBASICO").Range("B" & n).Value
'DEDUÇÃO
n = n + 2
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 18).Value = Sheets("ImportBASICO").Range("B" & n).Value
'VALOR DEVIDO
n = n + 2
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 19).Value = Sheets("ImportBASICO").Range("B" & n).Value

'********** B Á S I C O **********
'********** 1ª PARCELA
n = n + 4
'CUSTEIO
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 20).Value = Sheets("ImportBASICO").Range("B" & n).Value
'CAPITAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 21).Value = Sheets("ImportBASICO").Range("C" & n).Value
'TOTAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 22).Value = Sheets("ImportBASICO").Range("D" & n).Value
'A J U S T E CUSTEIO
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 29).Value = Sheets("ImportBASICO").Range("E" & n).Value
'A J U S T E CAPITAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 30).Value = Sheets("ImportBASICO").Range("F" & n).Value
'VALOR TOTAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 31).Value = Sheets("ImportBASICO").Range("G" & n).Value
'VALOR PAGO EM 2019
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 32).Value = Sheets("ImportBASICO").Range("H" & n).Value
'VALOR PAGO 2020 REF. A 2019
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 33).Value = Sheets("ImportBASICO").Range("I" & n).Value

'********** 2ª PARCELA
n = n + 1
'CUSTEIO
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 23).Value = Sheets("ImportBASICO").Range("B" & n).Value
'CAPITAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 24).Value = Sheets("ImportBASICO").Range("C" & n).Value
'TOTAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 25).Value = Sheets("ImportBASICO").Range("D" & n).Value
'A J U S T E CUSTEIO
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 34).Value = Sheets("ImportBASICO").Range("E" & n).Value
'A J U S T E CAPITAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 35).Value = Sheets("ImportBASICO").Range("F" & n).Value
'VALOR TOTAL
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 36).Value = Sheets("ImportBASICO").Range("G" & n).Value
'VALOR PAGO EM 2019
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 37).Value = Sheets("ImportBASICO").Range("H" & n).Value
'VALOR PAGO 2020 REF. A 2019
Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 38).Value = Sheets("ImportBASICO").Range("I" & n).Value
'********** FIM DO B Á S I C O **********

' Sheets("RESULTADO").Cells(ActiveCell.Row, ActiveCell.Column + 9).Value = Sheets("ImportBASICO").Range("C" & n).Value
Else
MsgBox "Não Localizado"
End If
End With
End If
n = n + 30
Next I


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Baldocchi
Colaborador
Colaborador
Mensagens: 15
Registrado em: Qua Ago 09, 2017 8:38 am

Re: erro: Estouro no laço For

Mensagem por Baldocchi »

Burro eu demais!

a variável tem que ser Long e eu coloquei Integer.

Como eu faço para apagar isto aqui?

desculpem-me!


Avatar do usuário
Reinaldo
Jedi
Jedi
Mensagens: 1537
Registrado em: Sex Ago 01, 2014 4:09 pm
Localização: Garça - SP / SCS - SP

Re: erro: Estouro no laço For

Mensagem por Reinaldo »

"...qualquer valor que eu coloque superior a 5000 dá erro ESTOURO..."
As variáveis Integer são armazenadas como números de 16 bits (2 bytes) com valor no intervalo de -32.768 a 32.767; assim não derá "Estourar" até atingir esse limite.
A rotina informada acima está restrita em 10.000 portanto não deveria interromper por esse erro;
exceto se o erro for pela variável N ter atingido esse limite.


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder