Application.ScreenUpdating = False not working switching between Excel sheets or workbooks - vba

The function Application.ScreenUpdating = False is not working whenever switching between worksheets or workbooks in Excel. This function alone worked fine in Excel 2010, but doesn't work in later versions from what I can tell. I am now using the office 365 desktop version of excel. In these later versions, the command only prevents updating when selecting cells or doing things within a specific worksheet, but for my purposes I need a form to pull data from a second worksheet which causes flickering.
Is there a way to prevent the screen from updating/flickering with SheetB briefly when it gets activated in this macro?
Sub ActivateSheetB()
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("SheetB").Activate
End Sub

I've had the same thing happen to me forever and it's fairly annoying but from my own observation, I believe that application.screenupdating = false is still working. What I mean by that is your code is still being sped up. Other than it visually being annoying and making users think they broke excel this is still an effective method for speeding up your workbook even when switching between sheets.
Hopefully someone comes along with a better answer than mine because I'd love to know what that answer is as well xD

Related

Excel VBA: efficient way to load data in a workbook with a lot of formulas

I have an Excel VBA code that reads the master data, load the data of each case/loop into a workbook, and then tons of calculations take place via numerous formulas (with no VBA codes). The desired result is the outputs of the calculations. The code loops through all the cases in the master data.
So here is the problem. I used multiple 'copy and paste' actions in each loop to load the data into the workbook, but the run time is way longer than I expected, causing Excel to be 'Not Responding'. Note that I already turned off automatic calculations in Excel and added the workbook Calculate trigger in the VBA code, so as to avoid updating the workbook entirely every time there is a paste action.
Could someone advise if directly setting the cells in the wb = the cells in the master data would speed up or slow down the code? Or could someone suggest a more efficient way of loading data?
I appreciate your effort before you send in your responses.
As said in the comments, not using .Select improves the speed of your macro. Also, copy paste actions are indeed more slow whith VBA and you should do assignations FromWorksheet.Range("CopyRange").Value = ToWorksheet.Range("PasteRange").Value. Also, it always helps to add these lines in the beginning:
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.DisplayAlerts = False
and reactivating them at the end:
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
There are many information on this, like this link

VBA Calculations Turning Back On Mid Execution

I'm running a large macro that includes various sub queries and functions.
Despite having the standard code to turn off calculations while the macro is running, somehow calculations are turned back on during the code execution.
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
I've added the above code the beginning of each major sub but still have the same issue. There's one point in the macro where I calculate the application to update a worksheet stored value, but I can't imagine that's what's causing it.
application.Calculate
Trying to find if there's a work around.

Excel 2013 crashes when unhiding columns

I've spent hours trying to figure this out with no solution being found so far. I have a macro (see below) that unhides/hides a range on a spreadsheet. Seems simple enough and the first two times I run this macro it works fine; however, the third time, which is always unhiding the range, usually causes Excel 2013 to crash. I read here that having an volatile user defined function in the range I'm unhiding might be causing the problem, but I already tried making the function not volatile and Excel still crashed. Does anyone have any ideas or experienced this before?
Sub HideShowSQLCreator(control As IRibbonControl)
Dim SQL_Creator As Range
Dim Report_Home_Cell As Range
Set SQL_Creator = Sheets("Report").Range("SQL_Creator")
Set Report_Home_Cell = Sheets("Report").Range("Report_Home_Cell")
If SQL_Creator.EntireColumn.Hidden = False Then
SQL_Creator.EntireColumn.Hidden = True
Report_Home_Cell.EntireRow.Select
ActiveWindow.FreezePanes = True
ActiveSheet.Range("Report_Home_Cell").Select
Exit Sub
End If
If SQL_Creator.EntireColumn.Hidden = True Then
SQL_Creator.EntireColumn.Hidden = False
ActiveWindow.FreezePanes = False
SQL_Creator.Select
Exit Sub
End If
End Sub
So, I got frustrated and figured the workbook was just corrupted so I created a new one from scratch. The macro was working fine until I got to the end and realized that the crash had to do with a big pivot table to the right of the range I was trying to hide/unhide. I'm not sure why it happened, but my solution was to just put the columns I was trying to hide/unhide in a separate sheet in the workbook. The macro works fine with them in separate sheets. Weird stuff, but I'm glad there was a solution in the end.

ScreenUpdating = False fails in Excel 2013 and 2016

Long-running, high-end Excel-based applications that I developed years ago and that run beautifully in Excel 2007 and 2010 look like Amateur Hour in Excel 2013 and 2016 because Application.ScreenUpdating = False no longer works reliably.
The screen unfreezes apparently when VBA code copies a preformatted worksheet from the macro workbook into a new workbook, although other circumstances must trigger it as well.
I’ve seen the threads on this subject that recommend “fiddling with the code” or “calling the code in a subroutine”. Unfortunately, I have to maintain hundreds of Excel applications each with thousands of lines of code and hundreds of users who are about to migrate to Office 2016, so rewriting is not an option. How can I recover Excel’s former elegance?
I wanted to leave a comment but I am not allowed to do so. Without a code sample it is very dificult to understand your problem (please see https://stackoverflow.com/help/how-to-ask and edit your question appropriately.
Here are some ideas:
- Check if your code calls for code in a different procedure, maybe the Application.ScreenUpdating is turned on outside of the procedure.
- Try this at the beginning of your procedure:
Application.Calculation = xlCalculationManual
Then, at the end of the code set it to:
Application.Calculation = xlCalculationAutomatic
It might help; however, without a code sample it is very difficult to properly help you.
Here is a technique that helps reduce flickering and preserves the StatusBar message.
Application.Cursor = xlWait
Application.ScreenUpdating = False
. . .
Set wkbNewBook = Workbooks.Add
ThisWorkbook.Windows(1).Visible = False
. . .
ThisWorkbook.Windows(1).Visible = True
wkbNewBook.Activate
Application.ScreenUpdating = True
Application.Cursor = xlDefault
We have been dealing with this problem now for a long time as my tools do show live animated charts which all of the sudden were completely static - we would have died for having at least a flickering animation.
Initially we tried to force the animation with a forced screenupdate but that did not work. Just by pure coincidence (copy pasted too many times) we stumbled into a solution which is equally unbelievable as it does seem to work. After each Application.ScreenUpdating = True we have added x3 times DoEvents. On some systems x2 times DoEvents works but x3 times does seem to be more reliable on the various office releases out there. Voila our animation came back :-)
Application.ScreenUpdating = True
DoEvents
DoEvents
DoEvents
We have not used it for the Application.ScreenUpdating = False statement but it might do some magic there. Anyway we hope that this road can help some of you finding creative functional solutions!
After looking through many forums, I believe the flicker problem is related to SDI vs MDI.
Someone suggested setting the application to not visible.
Application.Visible=False
enter code here
Application.Visible=True
This solved my flicker problem, but I didn't like how the excel application disappeared completely then suddenly reappeared for the user.
I was able to solve the issue to my liking by using a workaround this 'which window is on top' problem.
By leaving the main window alone, and forcing other workbooks to become not visible, letting the code run, then bringing them back to visible, it stopped flickering.
Application.Workbooks("yourworkbooktohide").Windows(1).Visible = False
Just remember to bring it back with =true.
Again, my script worked just fine in Excel 2010, but after "upgrading" to 2013, this flicker issue started.
For me, only "Application.ScreenUpdating = False" did not completely cure the flickering.
Calculation caused also the flickering.
Adding "Application.Calculation = xlCalculationManual" solved the flickering issue.
So, the code should be like:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
... inportant code here....
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Nico Mijnster.
I had the same problem and, believe it or not, it was solved by unplugging and reconnecting the cable of my second monitor. This cable is using a HDMI to VGA converter.

Closing a userform that is in workbook A from workbook B

I'm new to VBA so there might be a simple answer to this question but if there is I sure haven't found it. What I am doing is copying data from several workbooks into one master workbook. I have writen the code for this and it works fine. The only problem is the workbooks where I'm retriving the data have userforms that automatically initiate when the workbook is accesed. This means that when I run my code to copy the data it hangs at each userform and wont continue until I've physically closed each userform. So my question is: Is there a way to remotely close the userforms in the raw data workbooks from my master workbook VBA code? Thanks in advance.
to close all userforms, (if you want a specific one , change my code)
sub Close_Userforms()
Dim Form as VBA.Userform 'if not work change to Object
For each Form in VBA.Userform
'can add a condition, like : if Form.name ="Whatever" then
unload Form 'if you don't want to lose the data from the userforms, Form.Hide, and later re-loop and Form.Show
next Form
edit : can also if Typename (Form)="Whatever" then , for the condition
Assuming you mean that the forms pop up when you open the workbooks, disable events before doing so:
Application.Enableevents = False
Workbooks.Open ...
Application.Enableevents = True
for example.
I would suggest trying
Application.EnableEvents = False
Further reading.
Short description: All events (Workbook_Open, Workbook_BeforeSave etc), that usually fires upon opening or closing a workbook, will be ignored.
I have written the following functions to make all macros a bit simpler (and faster). Simply place these functions in a regular module.
Public Function CalcOff()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
End Function
Public Function CalcOn()
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Function
Begin your macro with:
CalcOff
And then end your macro with:
CalcOn
Remember that you need to put "CalcOn" in all places that exits the running macro.
Disabling ScreenUpdating makes the code "run in background" (nothing will be displayed).
Setting Calculation to manual improves the speed of the code, since no calculations will be made when changing data. But it's very important to exit all macros with "CalcOn", otherwise your sheet won't calculate (and that's not funny), and it will look like Excel has frozen (since ScreenUpdating would still be turned off).
However, if you by any chance happen to break a running code without exiting it the proper way (running "CalcOn"), simply close the Excel application and reopen it. Or run a macro that ends with the "CalcOn" code. Or create a new macro with that simple line.