force screen update VBA

dukeofscouts

Board Regular
Joined
Jan 19, 2009
Messages
146
Is there a way to force excel to make sure it is updating a screen before it runs the next line of code?

I'm playing with VBA, trying to expand my comfort with it. I've created a version of the popular SIMON game. HOWEVER, once every three code runs or so, the computer locks up, and rather than showing the correct sequence, it looks as if the sequence is all a repeat of the first button in the sequence. For example if the correct sequence was "A,B,C,D,A,C,D,B" what would show up on the screen is "A,A,A,A,A,A,A,A,".

Any suggestions?

Code:
Dim myCounter As Integer
myCounter = 1
For myCounter = 1 To Len(Range("s1").Value)
If Mid(Range("s1").Value, myCounter, 1) = "A" Then
fredForm.CommandButton1.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton1.BackColor = rgbRed
End If
If Mid(Range("s1").Value, myCounter, 1) = "B" Then
fredForm.CommandButton3.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton3.BackColor = rgbYellow
End If
If Mid(Range("s1").Value, myCounter, 1) = "C" Then
fredForm.CommandButton2.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton2.BackColor = rgbBlue
End If
If Mid(Range("s1").Value, myCounter, 1) = "D" Then
fredForm.CommandButton4.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton4.BackColor = rgbGreen
End If
Next myCounter
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,216,458
Messages
6,130,757
Members
449,588
Latest member
accountant606

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top