Okay, I could swear I am doing everything right. I click a button on Worksheet1 (for example) and it calls the following sub which deletes rows on the worksheet CrystalReport.
Everything runs fine EXCEPT that it is not actually deleting the rows. I am obviously missing something fundamental because I seem to have this issue a lot. I even did a WITH statement like I have been told to do before!
Code
Sub RemoveNonCRCClasses() Dim iFirstRow As Integer, iLastRow As Integer, iCurRow As Integer, iTotalRows As Integer, iPctCompl As Integer
Dim lNum As Long
Dim wsCR As Worksheet
Set wsCR = Worksheets("CrystalReport")
Call UnProtectWorksheet(wsCR)
'Start the progress bar
ImportProgressForm.Show (vbModeless)
ImportProgressForm.TaskLabel.Caption = "Importing Crystal Report Data" & vbNewLine & "and Removing Non-CRC Courses"
Progress (0)
With wsCR
.Visible = True
'Set the first and last row to loop through
iFirstRow = .UsedRange.Cells(1).Row
iLastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
iTotalRows = iLastRow - iFirstRow + 1
lNum = (-iFirstRow + 1) / iTotalRows
'Loop from iFirstRow to iLastRow
For iCurRow = iFirstRow To iLastRow
'Check the values in the first column
With .Cells(iCurRow, "A")
If Not IsError(.Value) Then
If .Value <> "CRC" And .Value <> "CAMPUS" Then
.EntireRow.Delete
'This will delete each row that does not contain the Values "CRC" or "CAMPUS"
End If
End If
End With
iPctCompl = Int((iCurRow / iTotalRows + lNum) * 100)
Progress (iPctCompl)
Next iCurRow
.Visible = False
End With
Unload ImportProgressForm
Call ProtectWorksheet(wsCR)
Set wsCR = Nothing
End Sub
Display More