I'm needing some help. A little
background; I have limited experience with VBA, but have done
extensive programming in Liberty Basic. The below code runs
lightening fast the first time you run it, but then takes up to two
minutes to run subsequent times. If I close Excel and reopen it, it
runs fast again on the first run, but then is slow after that once
again. Your help is greatly appreciated.
Sub SelectPackage()
Dim stag As String
Dim etag As String
Dim i As Integer
ActiveSheet.Unprotect
Application.ScreenUpdating = False
If Sheet1.Cells(20, 1) > 0 Then
stag = "<1lane>"
etag = "</1lane>"
End If
If Sheet1.Cells(21, 1) > 0 Then
stag = "<2lane>"
etag = "</2lane>"
End If
If Sheet1.Cells(22, 1) > 0 Then
stag = "<3lane>"
etag = "</3lane>"
End If
If Sheet1.Cells(23, 1) > 0 Then
stag = "<4lane>"
etag = "</4lane>"
End If
If Sheet1.Cells(24, 1) > 0 Then
stag = "<5lane>"
etag = "</5lane>"
End If
i = 3
While Not (Sheet13.Cells(i, 1) = stag)
Cells(i, 1).EntireRow.Hidden = True
i = i + 1
Wend
While Not (Sheet13.Cells(i, 1) = etag)
Cells(i, 1).EntireRow.Hidden = False
i = i + 1
Wend
Cells(i + 1, 1).EntireRow.Hidden = False
While Not (Sheet13.Cells(i, 1) = "</5lane>")
Cells(i, 1).EntireRow.Hidden = True
i = i + 1
Wend
Cells(i + 1, 1).EntireRow.Hidden = True
Application.ScreenUpdating = True
ActiveSheet.Protect
End Sub