#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Loop

The following code looks to see if an exam has gone or if there wasnt an
exam for that subjuect, hides the row the moves on untill the cell is blank.
However, when i run it, it goes into a continues loop. Any ideas as to why?
Thanks.

Private Sub Workbook_Open()
Application.ScreenUpdating = False
Sheets("Exam Timetable").Select
Range("A2").Select
Do
If ActiveCell.Value < Date Or ActiveCell.Value = "N/A" Then
Selection.EntireRow.Hidden = True
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell.Value = ""
End Sub


--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Loop

Hi
try something like the following instead:

Private Sub Workbook_Open()
Dim wks As Worksheet
Dim RowNdx As Long
Dim LastRow As Long

Application.ScreenUpdating = False
Set wks = Worksheets("Exam Timetable")

With wks
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 2 Step -1
If .Cells(RowNdx, "A").Value < Date Or _
.Cells(RowNdx, "A").Value = "N/A" Then
.Rows(RowNdx).Hidden = True
End If
Next RowNdx
Application.ScreenUpdating = True
End Sub

-----Original Message-----
The following code looks to see if an exam has gone or if

there wasnt an
exam for that subjuect, hides the row the moves on untill

the cell is blank.
However, when i run it, it goes into a continues loop.

Any ideas as to why?
Thanks.

Private Sub Workbook_Open()
Application.ScreenUpdating = False
Sheets("Exam Timetable").Select
Range("A2").Select
Do
If ActiveCell.Value < Date Or ActiveCell.Value

= "N/A" Then
Selection.EntireRow.Hidden = True
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell.Value = ""
End Sub


--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is

enough!"


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Christina Excel Discussion (Misc queries) 6 March 23rd 10 12:04 AM
for/next loop Poor Richard New Users to Excel 3 August 31st 09 09:28 PM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"