I have a procedure to sort and print a copy of the 'Summary' sheet of data - attendance records of a club.
As part of the procedure the data is first sorted on column L using the Named range PupilTotal.
This sorts the list in numerical order.
The procedure is then to delete rows where the value in col L is zero.
My problem is that it does not seem to delete every row where the value is zero.
In trying to resolve the problem I replaced the "cell.EntireRow.Delete" line with "cell.EntireRow.Font.Color = RGB(255, 0, 0)".
This does turn all rows wit zero in column L red.
So I do not understand why the delete line of code will not work for all the zero rows.
I am a relative newbie to VBA and my code has been put together by searching sites such as yours.
So any help or suggestions will be gratefully receive.
The code up to the delete row is as follows.
As part of the procedure the data is first sorted on column L using the Named range PupilTotal.
This sorts the list in numerical order.
The procedure is then to delete rows where the value in col L is zero.
My problem is that it does not seem to delete every row where the value is zero.
In trying to resolve the problem I replaced the "cell.EntireRow.Delete" line with "cell.EntireRow.Font.Color = RGB(255, 0, 0)".
This does turn all rows wit zero in column L red.
So I do not understand why the delete line of code will not work for all the zero rows.
I am a relative newbie to VBA and my code has been put together by searching sites such as yours.
So any help or suggestions will be gratefully receive.
The code up to the delete row is as follows.
Code:
Sub EndOfTermSortAndPrint()
'This code is linked to the "End of Term Print" button on Roll sheet.
'Prep for printing
'Minimise window
Application.ScreenUpdating = False
ActiveWindow.WindowState = xlMinimized
'Display Message Box
If MsgBox("This Procedure will print the Summary sheet." & vbNewLine & "Ensure printer in loaded and switched on." & vbNewLine & " " & vbNewLine & "Do you wish to proceed?", vbYesNo) = vbYes Then
GoTo 1 'i.e. get the code underway
Else
MsgBox "Routine Will Now End", vbCritical, "EXITING ROUINE"
ActiveWindow.WindowState = xlMaximized
Application.ScreenUpdating = True
ActiveSheet.Range("A1").Select
Exit Sub
End If
1 'Code start here
'Select Summary sheet and make a copy
Sheets("Summary").Select
Sheets("Summary").Copy
Dim cell As Range
Dim cell1 As Range
Dim cell2 As Range
Dim cell3 As Range
'Sort Pupil Total in Numerical order using range SortRange.
Worksheets("Summary").Activate
Range("SortRange").Select
Selection.Sort Key1:=Range("L11"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'Check column L - Pupil Total (named range PupilTotal = Col L ).
'If value is zero delete the row .
For Each cell In Range("PupilTotal")
If Not IsEmpty(cell) Then
If cell.Value = 0 Then
cell.EntireRow.Delete
End If
End If
Next