Hi,
I'm a newbie to VBA, and am trying to delete patients from a spreadsheet after they have been discharged. What happens is that the macro deletes the top line of an current patient, even if the value in cell AJ3 is 1 (i.e. patient is still in the center). Could you tell me what I'm doing wrong?
Thank you!
Barry
Sub RemoveDischargedAndBlanks()
Dim warning
warning = MsgBox(Range("A1").Value & "Warning: This will delete all discharged patients, and cannot be undone. Click OK to continue and delete, or Cancel to keep all patients.", vbOKCancel, "Warning")
If warning = vbCancel Then Exit Sub
ActiveSheet.AutoFilterMode = False
ActiveSheet.Range("$AJ$3:$AJ$1000000").Autofilter Field:=1, Criteria1:="0"
On Error Resume Next
ActiveSheet.Range("$AJ$3:$AJ$1000000").SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
ActiveSheet.AutoFilterMode = False
Range("B4:B8").Select
End Sub
Bookmarks