VBA - flickering after xlsheetvisible = true - excel

I've got a problem and really need some help from you. I was trying to google the solution, but found nothing useful. My macro runs by clicking on a commandbutton1 which is located on sheet1. Important detail: a chart is also located on sheet1.
The only thing the macro does is switching sheet2 from 'hidden' to 'visible'.
Sub abc()
Sheets(2).Visible = Not Sheets(2).Visible
End Sub
THE PROBLEM: after switching the sheet2 from hidden to visible the screen is flickering.
Notes:
The problem occurs only on the sheets with charts. It seems like excel is doing some chart update.
It occurs only when sheet2 is being switched to "visible".
I've tried:
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
I deleted any other macros and events in the workbook.
I've tried to run a macro directly from VBA editor (not via commandbutton1).
I've tried debugging step by step.
Is there anyone who can help me with this issue?

Related

How can I keep excel from "Not Responding", when running my refresh macro?

Through research, it seemed all I needed to do was use this? But my screen still bugs out while refreshing. I am just wanting the screen to not change or do anything at all when running this macro.
Application.ScreenUpdating = False
Here is just a small piece of my code that runs in this macro for reference:
Sub Refresh_Data()
Box.Show
Application.Cursor = xlWait
Application.ScreenUpdating = False
Workbooks("IOM Denial.xlsm").RefreshAll
Workbooks("IOM Denial.xlsm").Worksheets("Home").Activate
Application.Cursor = xlDefault
Application.ScreenUpdating = True
Unload Box
End Sub
You are showing the box in a modal form, Excel is waiting for a response from you before proceeding any further than Box.Show. If you close the Box using the little cross, your code should continue to run.
You can fix this in your code by changing the line to
Box.Show False '<-- runs non-modal
Information from Microsfot here: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/showmodal-property

VBA Textbox Autofilter hides everything

I implemented a google like search box into my spreadsheet, using an activex textbox.. However, in the beginning it worked fine, but now it hides the whole used range and i only see blank cells. This really needs to work 100%, but i can't figure out what's the problem.
The code is as follows:
Sub TextBox1_Change()
Application.ScreenUpdating = False
Range("$O$7").AutoFilter Field:=14, Criteria1:=TextBox1
End Sub
I'd appreciate your help with this issue.
I don't see any statement to clear previous filters, for example:
Worksheets(1).AutoFilterMode = False
Also, there should be Application.ScreenUpdating = True before End Sub to restore screen updating.
If TextBox1.vlaue = "" Then Application.Autofiltermode= False

Hiding the excels working with macro

I want to hide the excels while macros working on them. Application.visible is not working i don't know why. Is it possible for me to just write a code at the beginning so that until the end the excels won't be visible. Minimization is also works for me.
Thanks in advance
Are you calling it correctly? i.e.
Application.Visible = False
Alternatively you could 'freeze' the screen so you don't see anything whilst the macro is operating using:
Application.ScreenUpdating = False
I see Application.Visible is working fine for me.
I tried below code. I triggered below code on button click.
The Excel sheet is not displayed only excel icon was available on task bar.
Sub test()
Application.Visible = False
Cells(1, 1) = "Testing Visibility"
MsgBox "testing visibility"
ActiveWorkbook.Save
Application.Visible = True
End Sub

ScreenUpdating doesn't update screen in Excel 2013

I've code that takes 30+ mins to run. I have set screen updating to false while most of the code runs but every now and again I turn it to true and straight back to false.
In 2003, 2007 and 2010 this allows the screen to temporarily update. In 2013 it doesn't work.
How can I make Excel 2013 temporarily update the screen mid-macro?
Sub Test()
Application.ScreenUpdating = False
' Do loads of stuff here
Application.ScreenUpdating = True ' Enable to refresh screen
Application.ScreenUpdating = False ' Disable again
' Do more stuff here
Application.ScreenUpdating = True
End Sub
DoEvents worked for me. I don't know what causes this but inserting DoEvents in the Loop Method seems to correct the issue for me when I use it.
Sub LoopMethod
Foreach i in Identity
Call Loopthis
Next For
EndSub
Sub Loopthis
DoEvents
select.Cells(i, 6)
EndSub
I do place this code right before every event/screen I want to update and works fine for me:
Application.ScreenUpdating = True
DoEvents
Sheets("Main").Select 'Screen to update
Also I put the code inside every loop I use to write someting in the Sheet.
Activating another worksheet and then again activating the required worksheet worked for me - I had a code where the screen updating failed, I activated another worksheet and then again the one I was working on, it updated the current screen.
application.ScreenUpdating = False
''''''code'''''''
Thisworkbook.worksheets(any otherworksheet in workbook).activate
Thisworkbook.worksheets(current worksheet).activate
application.ScreenUpdating = True
As far as I have found the issue can be solved by jumping to another cell. You could do something like this:
Dim Ac as object
Set Ac = ActiveCell
Ac.Offset(0,IIf(Ac.Column = Application.Columns.Count, -1, 1)).Activate
Ac.Activate
As to the how or why of this behaviour I don't know (yet). As far as I have found now, it has something to do with the active cell before deactivating screen update, being the same as after reactivating screen update. But I haven

Launch a different sheet by Spin button

want to use a Spin button (ActiveX Control) to show a previous or next sheet. When the button is clicked the event is successfully triggered and the desired sheet is activated but it holds some elements (commands, graphs, etc.,) from the original sheet and shows these as an appending picture.
Sample code for Down button event :
Private Sub SpinButton_JumpToWeek_SpinDown()
Dim sh_num As String
Dim tmp_num As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False
SpinButton_JumpToWeek.Value = Range("B27").Value - 1
tmp_num = SpinButton_JumpToWeek.Value
' Activate desired KTx sheet
sh_num = "KT" & tmp_num
Range("F27").Value = "" 'reset to blank
Sheets(sh_num).Activate
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
To override this effect I have to manually select (activate) another sheet and then again select the desired sheet. I tried also to automatize this workaround with a macro, but unfortunately it does not work.
It is interesting that this problem do not occur if I execute code in Debug mode (using breakpoint and the stepping line by line).
Surprisingly, I do not have such problem if I try to show the previous/next sheet by writing a value (sheet name index) into a defined cell (i.e. using the Worksheet_Change event). The desired page is correctly shown. See photos.
Sample code for this evententer image description here:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh_num As String
Application.ScreenUpdating = False
Application.EnableEvents = False
If Range("F27").Value > 0 Then
' Activate desired KTx sheet
sh_num = "KT" & Range("F27").Value
Range("F27").Value = "" 'reset to blank
Sheets(sh_num).Activate
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
I need to use the Spin button because it is faster and allow me to skip some sheets (for example if these do not have data).
The problem occurs in both 32 and 64-bit Excel.
Do somebody an idea why this problem is occurring and a workaround? Do I have to change some settings or system properties in Excel? Any help would be highly appreciated.
#mehow
I append my commenst here due to large number of words.
I followed your suggestion and tried the example of a UserForm with inserted active control “Microsoft Office Spreadsheet”. I found out that this would not be a good solution for my case, because the response of such sheet is relatively slow (even on a fast PC like mine) when user inserts values into cells. Furthermore, this would greatly complicate my fairly simple *.xlsm workbook, which has more than 50 sheets (1 sheet for each week, the contents of these sheets are then linked to a main sheet), and completely meets my basic necessities (with the exception of this spin button of course).
In my opinion there is probably necessary to manipulate some kind of system property (like for e.g. Application.ScreenUpdating trick), but I do not have enough VBA knowledge to find it.
To clearly explain my question I would need to share my sample workbook, but I do not know how to upload it to this forum. Unfortunately, I am not able upload/show images successfully on this forum (due to my low rating), which would also help a lot.
BTW, I cannot see images on other questions of this forum, too. . Could this problem occur due to missing plugins in a web browser?
You can use a simple trick... before the "Application.screenupdating = true" you can insert the two lines:
ActiveWindow.SmallScroll Down:=-100
ActiveWindow.SmallScroll Up:=100

Resources