Results 1 to 2 of 2

Autofilter/delete empty rows is deleting non-empty rows!

Threaded View

  1. #1
    Registered User
    Join Date
    08-05-2009
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2003
    Posts
    61

    Autofilter/delete empty rows is deleting non-empty rows!

    Greetings, I'm currently running this code when the sheet deactivates to delete empty rows from a worksheet:

    Private Sub Worksheet_Deactivate()
    Application.ScreenUpdating = False
    Sheets("Records").Unprotect Password:="secret"
    
    With Worksheets("Records")
        .AutoFilterMode = False
        With Range("B2", Range("B" & Rows.Count).End(xlUp))
            .AutoFilter 1, "*Nil*"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        Sheets("Records").AutoFilterMode = False
    End With
    
    Sheets("Records").Protect Password "secret"
    Application.ScreenUpdating = True
    End Sub
    The problem is, if there are less than two records in the worksheet, it will delete the heading row, breaking my dynamic named ranges and tables based on same.

    I tried adding a check like this:
    If ActiveSheet.UsedRange.Rows.Count < 3 Then Exit Sub
    But this doesn't seem to work. Appreciate code / ideas to help!

    EDIT: I should add that a new row is generated automatically when the last record has been completed, in anticipation of the user needing to enter another record. But if they don't actually need to enter anything, then I have to remove that blank row so that my dynamic named ranges don't include it in the range, thus messing up tables/pivot tables.
    Last edited by oOarthurOo; 05-05-2010 at 11:03 AM. Reason: Clarification

Thread Information

Users Browsing this Thread

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

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