Results 1 to 15 of 15

Thread: [RESOLVED] Deleting row within a range now gives error 1004

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2012
    Posts
    90

    [RESOLVED] Deleting row within a range now gives error 1004

    The following code is set to delete any rows within the range 'picklist' where the value of column B is set to 'No'. This was working fine but now I just get a 'run time error 1004 - delete method of range class failed' at the .entirerow.delete. Even if I go back to an earlier version of the workbook then it runs fine but when I copy the same code to the latest version of the workbook then I get the error.

    Code:
        Const FilterString As String = "No"
        
        Dim lngLastRow As Long
        Dim rngToCheck As Range
        Dim xval As Variant
        Dim lcol As Long
        Dim xlCalc As XlCalculation
    
        Call FreezeScreen
            
        worksheets("sheet1").Unprotect
        
        With worksheets("sheet1").Range("PickList")
           .AutoFilter Field:=2, Criteria1:=FilterString
    
           On Error Resume Next
           .SpecialCells(xlCellTypeVisible).EntireRow.Delete     ' gives error at this point if I remove the on error line
           
           AutoFilter.ShowAllData
        End With
       
        worksheets("sheet1").Protect
        
        Call UnFreezeScreen
    Other modules called are below;

    Code:
    Sub FreezeScreen()
    
        With Application
    '        xlCalc = .Calculation
    '        .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
    End Sub

    Code:
    Sub UnFreezeScreen()
    
        With Application
    '        .Calculation = xlCalc
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
    End Sub
    Any idea what is causing the error?
    Last edited by scoobster; Jul 6th, 2012 at 07:29 AM. Reason: resolved issue

Posting Permissions

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



Click Here to Expand Forum to Full Width