ApplicationScreenUpdating causing screen button flicker

kalim

Board Regular
Joined
Nov 17, 2010
Messages
87
Hi excel users.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have a problem where, when I added Application.ScreenUpdating = False to my code it causes all the draw buttons to flicker each time it is run. <o:p></o:p>
<o:p></o:p>
Without having Application.ScreenUpdating = False in the code, it does not flicker at all. I added it only to speed the code up (which it does), but for some reason it causes all the draw shapes on the worksheet to flicker. This makes no sense to me as it should also stop screen flicker, which was never there to begin with... (using excel 2007)
<o:p></o:p>
Anyway code below. Full credit to Ruddles for the code <?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:shape style="WIDTH: 10.8pt; HEIGHT: 10.8pt; VISIBILITY: visible; mso-wrap-style: square" id=Picture_x0020_1 alt="0" type="#_x0000_t75" o:spid="_x0000_i1025"><v:imagedata src="file:///C:\Users\Stephen\AppData\Local\Temp\msohtmlclip1\01\clip_image001.gif" o:title="0"></v:imagedata></v:shape><o:p></o:p>



Code:
Public Sub ExtractRandomWord()
 
  Dim iLastRow As Long
  Dim iLastNew As Long
  Dim iPointer As Long
  Dim iInd As Long
  Dim iSwap As String
  Dim ws As Worksheet
  Set ws = Worksheets("data")
 
  Application.ScreenUpdating = False
 
  iLastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
  iLastNew = ws.Cells(Rows.Count, 3).End(xlUp).Row
 
  If iLastRow > 1 Then
    iPointer = WorksheetFunction.RandBetween(2, iLastRow)
    iLastNew = iLastNew + 1
    ws.Cells(iLastNew, 3) = ws.Cells(iPointer, 1)
    ActiveSheet.Shapes("TextBox 1").TextFrame.Characters.Text = ws.Cells(iPointer, 1)
    For iInd = iPointer To iLastRow + 1
      ws.Cells(iInd, 1) = ws.Cells(iInd + 1, 1)
    Next iInd
    iLastRow = iLastRow - 1
   If iLastRow = 1 Then ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Reset List"
  Else
    ActiveSheet.Shapes("TextBox 1").TextFrame.Characters.Text = ""
    For iPointer = 2 To iLastNew
      For iInd = iPointer + 1 To iLastNew
        If ws.Cells(iPointer, 3) > ws.Cells(iInd, 3) Then
          iSwap = ws.Cells(iPointer, 3)
          ws.Cells(iPointer, 3) = ws.Cells(iInd, 3)
          ws.Cells(iInd, 3) = iSwap
        End If
      Next iInd
      ws.Cells(iPointer, 1) = ws.Cells(iPointer, 3)
      ws.Cells(iPointer, 3).ClearContents
    Next iPointer
   ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Next Word"
  End If
 
 Application.ScreenUpdating = True
 
End Sub

Thanks.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
As far as I know, when you want something displayed in your computer screen... your do not use Application.ScreenUpdating = False, because this will stop Excel from rendering or drawing "images" to the screen (in your case "shapes"). The screen is flickering because, Excel waits for the code to reach Application.ScreenUpdating = = True... then render the images to the screen. Excel uses the Windows default printer driver to render or do the screen printing... (I am not sure if this statement is still true to Excel 2007 or 2010).
 
Upvote 0
OK thanks for the reply.

What can I add to the code to stop excel from redrawing these images every time then?

Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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