I keep getting a runtime 1004 error "unable to set FreezePanes of
the Window class" in this macro, AFTER they had been previously
set. I tried using activesheet, sh.FreezePanes = False,
Sheet.FreezePanes = False, and everything else I could think of, but
nothing seems to work. What am I doing wrong here? Or, since the
goal is simply to have the first row locked, so when the user
scrolls down, all the heading/labels follow them, anyone have any
other ideas? The code is:
Sub frezpanes()
Dim sh As Object
Sheets(1).Select
Application.EnableEvents = False
For Each sh In Sheets
sh.Activate
If ActiveWindow.FreezePanes = False Then
'do nothing
Else
ActiveWindow.FreezePanes = False
'<--error shows here
End If
If sh.Name = "Info" Then
'do nothing
ElseIf sh.Name = "Namelist" Then
'do nothing
ElseIf sh.Name = "Total Stats" Then
Rows("3:3").Select
ActiveWindow.FreezePanes = True
Range("B3").Select
Else
Rows("2:2").Select
ActiveWindow.FreezePanes = True
'<--error showed here2
Range("A2").Select
End If
Next sh
Application.EnableEvents = False
end sub
The first "if statement" was an attempt to correct the first error,
which is located where "'<--error showed here2" is in the code. My
thought was that the problem was that if the FreezePanes was already
set to "True",that it was firing the error. Apparently that's not
the case, so I'm a bit lost about what to correct.