Sheets names flashing up in duplicate when running vba

Kerryx

Well-known Member
Joined
May 6, 2016
Messages
766
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
1741600473960.png

When running my VBA code the sheet names flash up in duplicate at the bottom of the screen, any thoughts why.


VBA Code:
Sub Optimise(Flag As Boolean)
On Error Resume Next
F = Not Flag
Application.ScreenUpdating = F
Application.DisplayAlerts = F
Application.EnableEvents = F
Application.DisplayStatusBar = F
ActiveSheet.DisplayPageBreaks = F
If F = True Then
Application.Calculation = xlCalculationAutomatic
Else
Application.Calculation = xlCalculationManual
End If
On Error GoTo 0
End Sub

Sub Update()

'switch off updating to stop screen flickering

Optimise (True)

SheetList = Array("Leaderboard", "Entries_by_Name", "Points_by_League", "Tables", "Admin")


For Count = 0 To UBound(SheetList)

'Unprotect the sheets
Sheets(SheetList(Count)).Unprotect

'Add date and time to admin sheet
Sheets("Admin").Range("A2").Value = Now

Next


' Update - Refresh Queries
'
ActiveWorkbook.RefreshAll
DoEvents


' Sort the sheet

With ActiveWorkbook.Worksheets("Leaderboard").Sort
.SortFields.Clear
.SortFields.Add Range("P1"), , xlAscending 'Sort by Sort Help Help column P
.SortFields.Add Range("R1"), , xlDescending ' Sort by GD value
.SortFields.Add Range("D1"), , xlDescending 'Sort Total column

.SetRange Range("B1:R350")
.Header = xlYes

.Apply
End With
Sheets("Leaderboard").Select
Range("A1").Select

'Allow screen to update now

Optimise (False)

'Reprotect the modified sheets

For Count = 0 To UBound(SheetList)
'DoEvents
Do
    DoEvents
    Application.Calculate
Loop While Not CalculationState = xlDone

Sheets(SheetList(Count)).Protect

Next
'MsgBox "Job Done"

End Sub
 
Try selecting the query "fxTeamID" changing the properties to turn off background refresh (you have already done this on the others)
Save the spreadsheet.
Then rerun the code and see if the issue is gone.

Note: to reproduce the issue, it only happens if Leaderboard is not the active sheet. Moving selecting of the Leaderboard sheet before the Refresh all line, also resolves the issue.
 
Upvote 0
I am running out of ideas but give this a try.

VBA Code:
ActiveWindow.DisplayWorkbookTabs = False
DoEvents
ActiveWorkbook.RefreshAll
ActiveWindow.DisplayWorkbookTabs = True
 
Upvote 0

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