#How to update a worksheet only after N interactions of DO ..LOOPcycle?? URGENT!!!

R

rjmachado3

I get de following macro associated in a command button:

Private Sub cmdIniciar_Click()

Sheets("Folha1").Select
Do
tryes = tryes + 1
Sheets("Folha1").Range("b10").Value = tryes

If Sheets("Folha1").Range("b14").Value = True Then
End
End If
Loop
End Sub

The purpose is to produce one random aleatory data list, the problem
is that Excel 2003 refreshes permanently the aleatory cell data
witch makes consume all processor bandwidth. Want I need is that the
active worksheet "Folha1" only refreshes when the variable "tryes"
gets increments for 100 to 100 interactions (after only 100, 200, 300,
400, etc. interactions.) In this way I would economize the processor
bandwidth. I hope that I should be the best explicit as possible.
Sorry for the poor English. thanks for everyone that can help me!
 
R

rjmachado3

Maybe this?

Private Sub cmdIniciar_Click()

application.screenupdating = false

Sheets("Folha1").Select
Do
tryes = tryes + 1
Sheets("Folha1").Range("b10").Value = tryes

if tryes mod 100 = 0 then
application.screenupdating = true
doevents
end if

If Sheets("Folha1").Range("b14").Value = True Then
End
End If
Loop
End Sub

Sorry it doesn't work!!! What a shame :(
 
R

rjmachado3

Sorry it doesn't work!!! What a shame :(

All right I found the answer for the problem, it's this:

Private Sub cmdIniciar_Click()

Dim tryes As Variant

Application.ScreenUpdating = False

Sheets("Folha1").Select
Do
tryes = tryes + 1
Sheets("Folha1").Range("b10").Value = tryes

If tryes Mod 500 = 0 Then
Application.ScreenUpdating = True
DoEvents
End If
Application.ScreenUpdating = False

If Sheets("Folha1").Range("b14").Value = True Then
End
End If
Loop
End Sub
 
R

rjmachado3

All right I found the answer for the problem, it's this:

Private Sub cmdIniciar_Click()

Dim tryes As Variant

Application.ScreenUpdating = False

Sheets("Folha1").Select
Do
tryes = tryes + 1
Sheets("Folha1").Range("b10").Value = tryes

If tryes Mod 500 = 0 Then
Application.ScreenUpdating = True
DoEvents
End If
Application.ScreenUpdating = False

If Sheets("Folha1").Range("b14").Value = True Then
End
End If
Loop
End Sub

Sorry but the correct solution is this:
Private Sub cmdIniciar_Click()

Dim tryes As Variant

Application.ScreenUpdating = False

Sheets("Folha1").Select
Do
tryes = tryes + 1
Sheets("Folha1").Range("b10").Value = tryes

If Sheets("Folha1").Range("b14").Value = True Then
Application.ScreenUpdating = True
DoEvents
End
End If

If tryes Mod 500 = 0 Then
Application.ScreenUpdating = True
DoEvents
End If

Application.ScreenUpdating = False
Loop
End Sub
Only this is possible to make the program's stop in a middle of the
500 incrementations when the "B14" Cell test give "TRUE". Sorry for
anything lol :)
And thanks for the tips!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top