Screen updating turned off changes final result?

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
It appears that the intended formatting of this code (excerpt) does not work the same when used in conjunction with code that attempts to disable all screen updating (screen updating code posted further below):
Code:
'Fill the cells in the first row that contain anything with dark blue back and white font.
    Rows("1:1").AutoFilter
    Cells.EntireColumn.AutoFit
    Range("A1", Selection.End(xlToRight)).Select
    With Selection
        .Interior.ColorIndex = 55
        .Interior.Pattern = xlSolid
        .Font.ColorIndex = 2
    End With
'Goto top left most corner of sheet and freeze panes so the first row is frozen.
    Application.GoTo reference:=Range("A1"), Scroll:=True
    Range("A2").Select
    ActiveWindow.FreezePanes = True
    Application.GoTo reference:=Range("A1"), Scroll:=True

have a toggle as follows:
Code:
Sub ToggleEvents(blnState As Boolean)
'*********************************************
'*********************************************
'Toggles Display updates in Excel
'Written by Zack Barresse, aka firefytr
'*********************************************
'*********************************************
    With Application
        .DisplayAlerts = blnState
        .EnableEvents = blnState
        .ScreenUpdating = blnState
        If blnState = True Then
            .StatusBar = False
        End If
    End With
End Sub

For some reason, the first code works as intended if I do not toggle the screen updating off. When the toggling occurs the results of the formatting are different when the script is run as a whole. Specifically, several rows are formatted with respect to background and font color (rather than just the intended row 1)---and the freeze pane doesn't appear to freeze the first row but a subsequent row rather.

Any suggestions that point me in the right direction? (I suspect there will also be recommendations not to use the Select command either...alternative method welcomed).

Thank you in advance-
Chris
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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