I decided to go ahead and prefix all of the Cells(... rows with the SheetX
and it now runs fast everytime. I'm not sure why it would run fast the
first time and not on subsequent runs though. Strange. Anyway, here is my
final code that runs correctly;
Sub SelectPackage()
Dim StartingTag As String
Dim EndingTag As String
Dim i As Integer
i = 3
Sheet13.Unprotect
Application.ScreenUpdating = False
If Sheet1.Cells(20, 1) > 0 Then '\
StartingTag = "<1lane>"
EndingTag = "</1lane>"
ElseIf Sheet1.Cells(21, 1) > 0 Then ' \
StartingTag = "<2lane>"
EndingTag = "</2lane>"
ElseIf Sheet1.Cells(22, 1) > 0 Then ' > Defines what package to
un-hide
StartingTag = "<3lane>"
EndingTag = "</3lane>"
ElseIf Sheet1.Cells(23, 1) > 0 Then ' /
StartingTag = "<4lane>"
EndingTag = "</4lane>"
ElseIf Sheet1.Cells(24, 1) > 0 Then '/
StartingTag = "<5lane>"
EndingTag = "</5lane>"
End If
While Not (Sheet13.Cells(i, 1) = StartingTag) 'Hides all lines
before hitting the beginning of the defined
Sheet13.Cells(i, 1).EntireRow.Hidden = True
'package(StartingTag)
i = i + 1
Wend
While Not (Sheet13.Cells(i, 1) = EndingTag) 'Un-hides all lines
in the defined package (between StartingTag
Sheet13.Cells(i, 1).EntireRow.Hidden = False 'and EndingTag)
i = i + 1
Wend
Sheet13.Cells(i + 1, 1).EntireRow.Hidden = False 'Un-hides the line
containing EndingTag
While Not (Sheet13.Cells(i, 1) = "</5lane>") 'Hides all lines
after the defined package to the end of the
Sheet13.Cells(i, 1).EntireRow.Hidden = True 'packages (</5lane>
is the tag at the end of the last package)
i = i + 1
Wend
Sheet13.Cells(i + 1, 1).EntireRow.Hidden = True 'Hides the line
containing the last tag
Application.ScreenUpdating = True
Sheet13.Protect
End Sub