Results 1 to 11 of 11

Having trouble with VBA macro that deletes autofiltered rows

Threaded View

  1. #1
    Registered User
    Join Date
    06-14-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    6

    Having trouble with VBA macro that deletes autofiltered rows

    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
    Last edited by BChester; 06-15-2016 at 01:25 PM. Reason: Didnt comply with rule#3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro Deletes all rows except....
    By TheDriver85 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-25-2012, 06:37 PM
  2. [SOLVED] Macro which deletes rows
    By kjshep in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2012, 01:09 PM
  3. Macro that deletes rows below a certain value
    By Biased Historian in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-15-2011, 09:45 PM
  4. Macro which deletes rows stops at empty row
    By john_london in forum Excel General
    Replies: 17
    Last Post: 09-28-2010, 06:00 PM
  5. Macro for deleting autofiltered rows
    By tuph in forum Excel General
    Replies: 3
    Last Post: 12-17-2006, 10:30 PM
  6. Macro that Deletes All rows except first row
    By curtney in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2006, 01:22 PM
  7. [SOLVED] Macro that deletes certain rows only
    By supamari0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-09-2006, 11:15 AM
  8. [SOLVED] Macro that deletes certain rows and not others
    By Roger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-02-2005, 07:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1