# Excel VBA: Annoying blinking worksheet.



## miron_bsz (Jan 25, 2010)

Hello,

I'am using this simple code to refresh my quary tables:

With Worksheets("First")
.Range("A31").QueryTable.Refresh BackgroundQuery:=False
'worksheet blinks… arrrg
.Range("A31").QueryTable.Refresh BackgroundQuery:=False
'worksheet blinks… arrrg
.Range("A31").QueryTable.Refresh BackgroundQuery:=False
'worksheet blinks… arrrg
End with 

After each table refresh the worksheet blinks one time. It's quite annoying. I'd like to have a smooth refreshment. Can anyone please help?


----------



## SharksFan (Jan 25, 2010)

You can try to add this line of code before your refresh starts:

Application.ScreenUpdating = False

and then this line at the end:

Application.ScreenUpdating = True

The first line will tell Excel to suspend any screen updates (for as long as it is set to False), and then setting it to True afterwards will allow screen updates to occur again.

Hope this helps...


----------



## miron_bsz (Jan 25, 2010)

Thanks SharksFan!
 Ive changed my code as you suggested. Now it looks like that:

 Application.ScreenUpdating = False

 With Worksheets(First)
.Range("A11").QueryTable.Refresh BackgroundQuery:=False

.Range("A21").QueryTable.Refresh BackgroundQuery:=False

.Range("A31").QueryTable.Refresh BackgroundQuery:=False
End with

  Application.ScreenUpdating = True
 worksheet blinks arrrg

 But now Worksheet blinks at the end after this line Application.ScreenUpdating = True is executed. Is it possible to remove completely that annoying blinking effect?


----------



## n00bSauce (Dec 15, 2009)

I believe you might be fighting with the nature of the beast here. When you do a refresh, it literally redraws the screen - I don't know that there's a way around that really. 

Kudos to SharksFan though for that creative method of blinkage mitigation. :up:


----------



## SharksFan (Jan 25, 2010)

I agree with n00bSauce. It's just the way Excel handles QueryTable.Refresh and eventually Excel is going to try to refresh the screen.

Your only other option may be something more drastic (i.e. locking the window from screen updates at a lower level using the Windows API). Here is a link that might shed some light on using this technique:
http://relatedterms.com/thread/2007220/Screen flicker w Screen-Updating False 

Not sure if it will work in your case, but just another thought...


----------



## maxx_eclipse (May 29, 2007)

n00bsauce is spot on; It's a similar concept in Access, any refresh requires to essentially reload the whole project, whether it be a worksheet in Excel or a form/datasheet in Access.


----------



## nesr (Nov 5, 2008)

to eliminate screen blinking let the [Application.ScreenUpdating = True] be at the far end of your code unless it is necessary to update the screen, you can ignore putting it at all, as the Excel will update the screen automatically after executing the whole code.
moreover, try to close the VB editor before running the code, this will speed it up efficiently, and will enhance the program activity.
regards..


----------

